python
1
CSCE 3600: Systems Programming
Minor Assignment 6 – Python and C
Due: Wednesday, December 4, 2019 at 11:59 PM
PROGRAM DESCRIPTION:
In this assignment, you will compare the performance of a scientific computation performed in C and the same computation performed in Python. You will implement the multiplication of two square matrices each of dimensions 1000 by 1000. Let us denote the input matrices as A and B. Let us denote the output matrix as C.
Your C program skeleton is given below:
#include<stdio.h>
#define N 1000
int A[N][N];
int B[N][N];
int C[N][N];
int main(int argc, char ** argv)
{
int i,j,k;
int m=0;
for (i=0;i<N;i++) {
for (j=0;j<N;j++) {
A[i][j]=m++;
}
}
m=0;
for (i=0;i<N;i++) {
for (j=0;j<N;j++) {
B[i][j]=m++;
}
}
for (i=0;i<N;i++) {
for (j=0;j<N;j++) {
C[i][j]=0;
}
}
/* Your matrix multiplication code goes here */
return 0;
}
2
Use the above C code as your skeletal code and insert the matrix multiplication code below the comment provided.
Save your C code as <euid>_6.c, where <euid> is your EUID.
Compile it first with –g flag and produce the binary <euid>_unopt.out
gcc -g –o <euid>_unopt.out <euid>_6.c
Run it 5 times and measure the average time taken.
Compile it first with –O3 flag and produce the binary <euid>_opt.out
gcc -O3 –o <euid>_opt.out <euid>_6.c
Run it 5 times and measure the average time taken.
For all time measurements, for simplicity, simply use the time command. See additional help document included on Canvas related to the ‘time’ command.
Eg:
$>time ndg0068_unopt.out
real 0m0.017s user 0m0.013s sys 0m0.005s
Pick the ‘user’ time from the above.
Your Python code skeleton is given below:
import numpy as np
N=1000
A = np.arange(N*N).reshape(N,N)
B = np.arange(N*N).reshape(N,N)
# Insert your one line call to compute
# The Multiplication of A and B
# HINT HINT: Use the dot function supplied by numpy
Save your Python code as <euid>_6.py, where <euid> is your EUID.
Run it 5 times and measure the average time taken.
3
For all time measurements, for simplicity, simply use the time command:
Eg:
$>time python ndg0068_6.py
Your submission on Canvas must include:
1. C source code
2. Python source code
3. A text file (named <euid>.txt) 15 time readings as shown below:
python c_unopt c_opt
0m1.096s 0m.011s 0m.005s
0m1.232s 0m.013s 0m.006s
…
0m1.172s 0m.012s 0m.004s
Observations on CSE01 machine:
Python 2.7.15+ is already installed
ndg0068@cse01: $ which python /usr/bin/python
numpy package required is also already installed
Compare the Python code (5 lines of non-blank code) with the length of your C
code. What can you conclude?
Compare the run-time of your Python code with the run-time of your compiled C
code (unoptimized and optimized). What can you conclude?
Between the unoptimized and optimized versions of your compiled C code, how
much faster is your optimized version?
REQUIREMENTS:
C source file shall be named <euid>_6.c
Python source file shall be named <euid>_6.py
Results text file shall be named <euid>.txt
Test out your results on our CSE machines (e.g., cse01, cse02, …, cse06), to
make sure that they indeed work.
Your programs will be graded based largely on whether it works correctly on the
CSE machines (e.g., cse01, cse02, …, cse06), so you should make sure that
your program runs on a CSE machine. Please include any special instructions
required to run your Python program including making sure numpy package is
available.
4
This is an individual programming assignment that must be the sole work of the individual student. Any instance of academic dishonesty will result in a grade of “F” for the course, along with a report filed into the Academic Integrity Database.
SUBMISSION:
You will electronically submit your solutions (.c, .py and .txt files) to the Minor 6
dropbox in Canvas by the due date and time.