Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Introduction time a simple C program with different compiler options. In order to do this lab, you will need to know how to set various

Introduction
 time a simple C program with different compiler
options. In order to do this lab, you will need to know how to set various
options to the C compiler. You are required to use gcc under a
UNIX/LINUX environment. If you are using Windows, you can easily
download and install Cygwin to get a UNIX environment. gcc has different
optimization levels, which are controlled by "-O" option, with -O0 as no
optimization and -O3 as the highest level of optimization. Consult the man
pages for the detailed settings of the compiler.
Here is the C program for the matrix multiplication, i.e., matmul.c, that
computes the production of two matrices Amxn × Bnxk. It takes three input
parameters, i.e., m, n, and k, randomly generates two matrices, and then
computes their product. In this lab, we will compile and time this C program
using different compilation options and examine optimized and unoptimized
code produced by the compiler.
Objective
1. To become familiar with how to measure the performance of a computer
2. To understand the difference between CPU time and wall clock time
3. To see the effects of different compiler options on the program code

1. Download matmul.c and study the source code;
2. Setup the Unix/Linux environment and GCC compiler if needed;
3. Compile matmul.c using four different optimization levels in GCC, i.e., -O0, -
O1, -O2, -O3 into four different executables. e.g.:
gcc -O0 -o matmu0 matmul.c
gcc -O1 -o matmu1 matmul.c
gcc -O2 -o matmu2 matmul.c
gcc -O3 -o matmu3 matmul.c
4. For each of the executables obtained above, vary the inputs to each of the
executables, collect the required CPU times and latencies, and fill in Tables 1
and 2.
Questions
1. What are the differences between function clock() and gettimeofday() in matmul.c
when measuring time? To evaluate the performance of a program or a processor,
which function should we use and why?
2. Does a higher-level compilation optimization always help to reduce the CPU
time from your experiments? How about program size?
3. Does a program with a smaller program size always have a shorter execution
time?

 

 

 

Lab 1: Performance measurement and optimization
3
What/how to hand in
You need to submit a well-typed written report and a video in Canvas. Your report should
present your experimental results (with tables and/or figures) and show your
understanding of the contents we discuss in the class by clearly interpreting these results
and/or answering the questions. A summary section is mandatory that summarizes the
general observations, experiences, and conclusions you obtained from this project.
The video can be a Youtube link (put it in your report) or a video file with a 1 - 2 minute
video with explanations demonstrating that you have completed the lab and your lab/code
works correctly. Be sure to show your PID or speak clearly your name and PID in your
video submission.
Table 1 CPU Times and Wall-Clock Times Comparisons for Different Programs
with Different Compilation Optimizations
CPU Time vs. Wall-Clock Time (seconds)
Compilation
Options -O0 -O1 -O2 -O3
Matrices Size
(m=n=k)
CPU
Time
Wall-Clock
Time
CPU
Time
Wall-Clock
Time
CPU
Time
Wall-Clock
Time
CPU
Time
Wall-Clock
Time
200
400
600
800
1000
1200
Table 2 The Code Sizes of Executables with Different Compilation Optimization
Levels
Compilation
Options -O0 -O1 -O2 -O3
Executables
(BYTES)
Reference
1. Cygwin https://www.cygwin.com/
2. Use the Unix man command to read manual pages (iu.edu)
https://kb.iu.edu/d/afjm
3. UNIX Survival Guide: A User Manual, https://ts.vcu.edu/askit/research-math-
science/unix-for-researchers-at-vcu/unix-survival-guide-a-user-manual/
4. GCC Command Options https://gcc.gnu.org/onlinedocs/gcc/Invoking-GCC.html



Step by Step Solution

3.34 Rating (145 Votes )

There are 3 Steps involved in it

Step: 1

To address this lab assignment youll follow these steps 1 Download matmulc Obtain the source code for the matrix multiplication program named matmulc ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Auditing and Assurance services an integrated approach

Authors: Alvin a. arens, Randal j. elder, Mark s. Beasley

14th Edition

133081605, 132575957, 9780133081602, 978-0132575959

More Books

Students also viewed these Algorithms questions

Question

give guidelines for improving exercise adherence.

Answered: 1 week ago