A) What's the major difference between the two programs? B) Which program has better cache performance? Why? (Hint: try different input arguments) C) Use the example in the lab slides to print the execution time of each program. Submit your code and explain if the execution time(s) valid your answer to the previous question.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Topic Video
Question

Please send me answer answer of this question immediately please.send typed answer i will rate u sure sir 

A) What's the major difference between the
two programs?
B) Which program has better cache
performance? Why? (Hint: try different input
arguments)
C) Use the example in the lab slides to print
the execution time of each program. Submit
your code and explain if the execution time(s)
valid your answer to the previous question.
rit
Ail
#include <stdio.h>
#include <stdlib.h>
tic
int** genRandomMatrix (int n, int max) {
int i, j;
int** mat = malloc(n* sizeof(int*));
for (i=0; i<n; i++) {
mat [i] = malloc (n *sizeof(int));
for (j=0; j<n; j++)
mat[i][j] = 1 + rand() % max; //generate random number between 1 to max
}
void free_all(int** mat, int n) {
int i;
for (i=0; i<n; i++)
free (mat[i]);
}
}
return mat;
float averageMat_v2 (int** mat, int n) {
int i, j, total=0;
for (i = 0; i<n; i++){
}
free (mat);
D}
S int main(int argc, char** argv) {
if (argc != 2) {
for (j = 0; j<n; j++){
total= mat [j][i];
}
}
}
return (float) total/(n*n);
}
Show Transcribed Text
fprintf(stderr, "usage: %s <n>\n", argv[0]);
fprintf(stderr, "where <n> is the dimension of the matrix\n");
return 1;
printf("matrix size is %d\n", n);
printf("matrix mean is %f\n", res2);
free_all(matrix, n);
return 0;
#include <stdio.h>
#include <stdlib.h>
}
int n = strtol(argv[1], NULL, 10); //converts the string to a decimal int (base 10, decimal)
int ** matrix = genRandomMatrix (n, 100);
float res2= averageMat_v2(matrix, n);
int** genRandomMatrix(int n, int max) {
int i, j;
int** mat malloc(n* sizeof(int*));
for (i=0; i<n; i++){
mat[i] = malloc (n* sizeof(int));
}
void free_all(int** mat, int n) {
int i;
for (i=0; i<n; i++)
}
return mat;
free (mat[i]);
for (j=0; j<n; j++)
mat [i][j] = 1 + rand() % max; /*generate random number between 1 to max */
free (mat);
float averageMat_v1(int** mat, int n) {
int i, j, total=0;
for (i = 0; i<n; i++){
for (j = 0; j<n; j++){
total+= mat[i][j];
3
}
}
return (float) total/(n*n);
}
int main(int argc, char** argv) {
if (argc != 2) {
Ć
J
}
int n = strtol(argv[1], NULL, 10);
int ** matrix = genRandomMatrix(n, 100);
float res1 = averageMat_v1(matrix, n);
printf("matrix size is %d\n", n);
printf("matrix mean is %f\n", res1);
free_all(matrix, n);
return 0;
c
fprintf(stderr, "usage: %s <n>\n", argv[0]);//converts the string to a decimal int (base 10, decimal)
fprintf(stderr, "where <n> is the dimension of the matrix\n");
return 1;
Transcribed Image Text:A) What's the major difference between the two programs? B) Which program has better cache performance? Why? (Hint: try different input arguments) C) Use the example in the lab slides to print the execution time of each program. Submit your code and explain if the execution time(s) valid your answer to the previous question. rit Ail #include <stdio.h> #include <stdlib.h> tic int** genRandomMatrix (int n, int max) { int i, j; int** mat = malloc(n* sizeof(int*)); for (i=0; i<n; i++) { mat [i] = malloc (n *sizeof(int)); for (j=0; j<n; j++) mat[i][j] = 1 + rand() % max; //generate random number between 1 to max } void free_all(int** mat, int n) { int i; for (i=0; i<n; i++) free (mat[i]); } } return mat; float averageMat_v2 (int** mat, int n) { int i, j, total=0; for (i = 0; i<n; i++){ } free (mat); D} S int main(int argc, char** argv) { if (argc != 2) { for (j = 0; j<n; j++){ total= mat [j][i]; } } } return (float) total/(n*n); } Show Transcribed Text fprintf(stderr, "usage: %s <n>\n", argv[0]); fprintf(stderr, "where <n> is the dimension of the matrix\n"); return 1; printf("matrix size is %d\n", n); printf("matrix mean is %f\n", res2); free_all(matrix, n); return 0; #include <stdio.h> #include <stdlib.h> } int n = strtol(argv[1], NULL, 10); //converts the string to a decimal int (base 10, decimal) int ** matrix = genRandomMatrix (n, 100); float res2= averageMat_v2(matrix, n); int** genRandomMatrix(int n, int max) { int i, j; int** mat malloc(n* sizeof(int*)); for (i=0; i<n; i++){ mat[i] = malloc (n* sizeof(int)); } void free_all(int** mat, int n) { int i; for (i=0; i<n; i++) } return mat; free (mat[i]); for (j=0; j<n; j++) mat [i][j] = 1 + rand() % max; /*generate random number between 1 to max */ free (mat); float averageMat_v1(int** mat, int n) { int i, j, total=0; for (i = 0; i<n; i++){ for (j = 0; j<n; j++){ total+= mat[i][j]; 3 } } return (float) total/(n*n); } int main(int argc, char** argv) { if (argc != 2) { Ć J } int n = strtol(argv[1], NULL, 10); int ** matrix = genRandomMatrix(n, 100); float res1 = averageMat_v1(matrix, n); printf("matrix size is %d\n", n); printf("matrix mean is %f\n", res1); free_all(matrix, n); return 0; c fprintf(stderr, "usage: %s <n>\n", argv[0]);//converts the string to a decimal int (base 10, decimal) fprintf(stderr, "where <n> is the dimension of the matrix\n"); return 1;
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Instruction Format
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education