Write a C programming language console program of the vector multiply-add “axpy”
ID: 3705631 • Letter: W
Question
Write a C programming language console program of the vector multiply-add “axpy” algorithm for double precision floating data types: z[i] = (a*x[i]) + y[i].
Your C program should be single threaded, and sequential. Execution should be scalable and be able to handle the number of vector elements, N, from 1 to 1,000,000. Set the vector/array dimension using a DEFINE statement. Use a random number generator which every time the program is executed fills the random data into the scalar and vector elements with random double precision floating point values ranging from 1 to 100 The console window should execute and remain open until manually closed. Comment your code to explain what it is doing.
You should use the time.h header file library, and either the “time_t or clock_t timer functions to capture the start and end execution times for your benchmark. You will need to use an outer accuracy improvement loop in your program. Adjust the total number of iterations of your inner and outer accuracy improvement loops so that total execution time is approximately constant as you vary the dimensions of your x, y and z arrays from 1 to 1,000,000.
Your console program should print out ( using formatted printf commands )
1) your name and the programming exercise number
2) Processor name
3) Processor Clock frequency
4) the vector/array dimension
5) # of accuracy loops,
6) total measured execution time,
7) evaluated execution time to the entire array,
8) evaluated execution time per array element,
9) evaluated execution time per arithmetic operation,
10) evaluated cycles per arithmetic Op,
11) evaluated Ops per cycle, and
12) evaluated double precision operations per second
Explanation / Answer
# include < stdio.h >
# include < time.h >
# include < stdio.h >
# include < math.h >
# define MAX 5000 double random_generated()
{
return 1.0+ { (double)rand()/Rand_MAX)*100:// double
precision random number between 1 to 100
}
int main ()
{ clock _ t total _ t total _ t = clock();// total execution time
Double X[MAX];//
vectars X,Y,Z: double Y[MAX]: double Z[MAX]
int I : int a = 10
double total _ time = 0.0
double total _ array _ time =0.0
double total _ arithmetic _ time = 0.0
double total _ elm _ time = 0.0
clock _ t array _ t ;
clock _ t arth _ time;
clock _ t elm _ time
array _ t = clock();
for( i = 0; i < MAX ; i + t)
{
elm _ time = clock():
X(i) = random _ generated () :
Y(i) = random _ generated () :
Arth _ time = clock() :
Z[i] = a* x[i]:
Z[i] = Z[i]+4[i]:
total _ arithmetic _ time + ((double)arth _ time)/ clock _ per _ sec : in seconds//
elm _ time = clock () _ elm _ time; total _ elm _ time + = ((double)elm _ time)/clocks _ per _ sec ; // in seconds
}
Array _ t = clock () _ array _ t ; total _ array _ time = ((double) array_ t)/clocks _ per _ sec;
total _ t = clock () _ total _ t ; total _ time = ((double)total _ t)/clocks _ per _ sec; // in seconds //
Print f ( “ Processor : i3 ”})
Print f (“ Processor clock frequency : 2.00 GHz ”) ;
Print f ( “Total Exectution time = % if ,” total _ time) ;
Print f (“ Total Array time = % if ”, total _ array _ time);
Print f ( “ Total time per array element = % if ” total _ elm _ time/MAX);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.