Question: Based on the C code given below, matrix_initialize_unopt is an unoptimized version of matrix initialiaztion and matrix_initialize_opt is an optimized version of matrix initialization. How would matrix_initialize_opt be written? #define X 500 #define Y 12 #define Z 8 struct fn_args { int n; int *mem1; int *mem2; }; void set(int *mat, int i, int num) { mat[i] = num; } void matrix_initialize_unopt(struct fn_args *args) { int i, j, n; int *mat1, *mat2; n = args->n; mat1 = args->mem1; mat2 = args->mem2; for (i = 0; check(i, n); i++){ for (j = 0; check(j, n); j++){ set(mat1, i * n + j, i); set(mat2, i * n + j, i+1); } } } void matrix_initialize_opt(struct fn_args *args) { // XXX: optimized implementation goes here }

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter7: Arrays
Section: Chapter Questions
Problem 9PP: (Data processing) Your professor has asked you to write a C++ program that determines grades at the...
icon
Related questions
Question
Question: Based on the C code given below, matrix_initialize_unopt is an unoptimized version of matrix initialiaztion and matrix_initialize_opt is an optimized version of matrix initialization. How would matrix_initialize_opt be written? #define X 500 #define Y 12 #define Z 8 struct fn_args { int n; int *mem1; int *mem2; }; void set(int *mat, int i, int num) { mat[i] = num; } void matrix_initialize_unopt(struct fn_args *args) { int i, j, n; int *mat1, *mat2; n = args->n; mat1 = args->mem1; mat2 = args->mem2; for (i = 0; check(i, n); i++){ for (j = 0; check(j, n); j++){ set(mat1, i * n + j, i); set(mat2, i * n + j, i+1); } } } void matrix_initialize_opt(struct fn_args *args) { // XXX: optimized implementation goes here }
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Computational Systems
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
New Perspectives on HTML5, CSS3, and JavaScript
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning