Program a: program written in C that sums an array of 50 elements (without loop unrolling) #include int main() { int arr[50] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50}; int sum = 0; int i; // Sum the array elements using a loop for (i = 0; i < 50; i++) { sum += arr[i]; } printf("Sum: %d\n", sum); return 0; } Program b: optimized code using loop unrolling #include int main() { int arr[50] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50}; int sum = 0; int i; // Sum the array elements using loop unrolling for (i = 0; i < 50; i += 4) { sum += arr[i] + arr[i + 1] + arr[i + 2] + arr[i + 3]; } printf("Sum: %d\n", sum); return 0; } using Program A and B above generate a graph of performance improvement to compare the program with loop unrolling and the program without loop unrolling
int main() {
int arr[50] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50};
int sum = 0;
int i;
// Sum the array elements using a loop
for (i = 0; i < 50; i++) {
sum += arr[i];
}
printf("Sum: %d\n", sum);
return 0;
} Program b: optimized code using loop unrolling #include <stdio.h>
int main() {
int arr[50] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50};
int sum = 0;
int i;
// Sum the array elements using loop unrolling
for (i = 0; i < 50; i += 4) {
sum += arr[i] + arr[i + 1] + arr[i + 2] + arr[i + 3];
}
printf("Sum: %d\n", sum);
return 0;
} using Program A and B above generate a graph of performance improvement to compare the program with loop unrolling and the program without loop unrolling

Step by step
Solved in 3 steps









