This is a UNIX activity that I have to modify and run this program. show me your
ID: 3859355 • Letter: T
Question
This is a UNIX activity that I have to modify and run this program.
show me your work and please modify dot1m.c and dot1s.c so that I can the result of this program.
1. Compile and run the programs (and name the executable dots1 and dotm1 respectively).
Use time to get the 3 times of the program run. For example,
time ./dots1
2. Modify dots1.c so that it will take the value for VECLEN from an argument. That is, to run the program (the executable is dots).
time ./dots1 1000000
3. Modify dotm1.c so that it will take and set the values for VECLEN and NUMTHRDS from two arguments. That is, to run the program where the value of VECLEN*NUMTHRDS for dotm1.c should be equal to the value of VECLEN of dots1.c
time ./dotm1 10 100000
4. Run dots1 and dotm1 with the various size. For example,
time ./dots1 32000000
time ./dotm1 2 16000000
time ./dotm1 4 8000000
time ./dotm1 8 4000000
time ./dotm1 16 2000000
time ./dotm1 32 1000000
** Summarize the results of each run (serial versus thread program run, and the number of threads for each result).
5. Submit a word document to show your work done (with the source code and runs in the document). Provide a proper headings for each code listing and the run of the programs.
Explanation / Answer
Hi,
Please check now
#include <stdio.h>
#include <stdlib.h>
/*
The following structure contains the necessary information
to allow the function "dotprod" to access its input data and
place its output so that it can be accessed later.
*/
typedef struct
{
double *a;
double *b;
double sum;
int veclen;
int NUMTHRDS;
} DOTDATA;
// int VECLEN = 1000000;
DOTDATA dotstr;
/*
We will use a function (dotprod) to perform the scalar product.
All input to this routine is obtained through a structure of
type DOTDATA and all output from this function is written into
this same structure. While this is unnecessarily restrictive
for a sequential program, it will turn out to be useful when
we modify the program to compute in parallel.
*/
void dotprod()
{
/* Define and use local variables for convenience */
int start, end, i;
double mysum, *x, *y;
start=0;
end = dotstr.veclen;
x = dotstr.a;
y = dotstr.b;
/*
Perform the dot product and assign result
to the appropriate variable in the structure.
*/
mysum = 0;
for (i=start; i<end ; i++)
{
mysum += (x[i] * y[i]);
}
dotstr.sum = mysum;
}
/*
The main program initializes data and calls the dotprd() function.
Finally, it prints the result.
*/
int main (int argc, char *argv[])
{
// modify the program to get VECLEN as the argument1
// that is, run the program: ./dots 100000
//
int VECLEN = 1000000;
int i,len,NUMTHRDS;
double *a, *b;
/* Assign storage and initialize values */
len = VECLEN;
a = (double*) malloc (len*sizeof(double));
b = (double*) malloc (len*sizeof(double));
for (i=0; i<len; i++) {
a[i]=1;
b[i]=a[i];
}
dotstr.veclen = len;
dotstr.a = a;
dotstr.b = b;
dotstr.sum=0;
/* Perform the dotproduct */
dotprod ();
/* Print result and release storage */
printf ("Sum = %f ", dotstr.sum);
free (a);
free (b);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.