Programming Assignment Multi-Threading and Debugging 2

Similar documents
Programming Assignment 3 (PA3) - Popular Names

Programming Assignment 4 (PA4) - myxd Milestone Due: Final Due:

Programming Assignment 1 (PA1) - Display Bowtie

Programming Assignment 2 (PA2) - Binary Clock

Programming Assignment 2 ( 100 Points )

Lab 09 - Virtual Memory

The following program computes a Calculus value, the "trapezoidal approximation of

Programming Assignment 8 ( 100 Points )

COMP 321: Introduction to Computer Systems

Project 1. 1 Introduction. October 4, Spec version: 0.1 Due Date: Friday, November 1st, General Instructions

a) Do exercise (5th Edition Patterson & Hennessy). Note: Branches are calculated in the execution stage.

CS143 Handout 05 Summer 2011 June 22, 2011 Programming Project 1: Lexical Analysis

Computer Science 322 Operating Systems Mount Holyoke College Spring Topic Notes: C and Unix Overview

The Shell, System Calls, Processes, and Basic Inter-Process Communication

ECE 2400 Computer Systems Programming, Fall 2018 PA2: List and Vector Data Structures

CS61C Machine Structures. Lecture 3 Introduction to the C Programming Language. 1/23/2006 John Wawrzynek. www-inst.eecs.berkeley.

C++ for Java Programmers

Programming Assignment 5 (100 Points) START EARLY!

Operating Systems (234123) Spring (Homework 3 Wet) Homework 3 Wet

CS242: Object-Oriented Design and Programming

Provided by - Microsoft Placement Paper Technical 2012

CS Homework 11 p. 1. CS Homework 11

ECE 2400 Computer Systems Programming, Fall 2017 Programming Assignment 3: Sorting Algorithms

ENCM 369 Winter 2019 Lab 6 for the Week of February 25

CS 1110, LAB 3: MODULES AND TESTING First Name: Last Name: NetID:

In either case, remember to delete each array that you allocate.

Programming Assignment #4 Arrays and Pointers

Project Introduction

Lecture 03 Bits, Bytes and Data Types

1. Introduction. 2. Deliverables

ITCS 4145/5145 Assignment 2

When you add a number to a pointer, that number is added, but first it is multiplied by the sizeof the type the pointer points to.

Effective Programming in C and UNIX Lab 6 Image Manipulation with BMP Images Due Date: Sunday April 3rd, 2011 by 11:59pm

Creating a Shell or Command Interperter Program CSCI411 Lab

Operating Systems (234123) Spring 2017 (Homework Wet 1) Homework 1 Wet

Here's how you declare a function that returns a pointer to a character:

Raspberry Pi Basics. CSInParallel Project

It is academic misconduct to share your work with others in any form including posting it on publicly accessible web sites, such as GitHub.

CSE 333 Midterm Exam July 24, Name UW ID#

CSE 333 Midterm Exam 7/29/13

Programming Assignment #3 Event Driven Simulation

Final Project: LC-3 Simulator

Cosc 242 Assignment. Due: 4pm Friday September 15 th 2017

Project #1: Tracing, System Calls, and Processes

CS Homework 11 p. 1. CS Homework 11

Project #1 Exceptions and Simple System Calls

EE355 Lab 5 - The Files Are *In* the Computer

Laboratory Assignment #4 Debugging in Eclipse CDT 1

15-110: Principles of Computing, Spring 2018

CS354 gdb Tutorial Written by Chris Feilbach

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function

CS Homework 10 p. 1. CS Homework 10

CSCI0330 Intro Computer Systems Doeppner. Lab 02 - Tools Lab. Due: Sunday, September 23, 2018 at 6:00 PM. 1 Introduction 0.

Carnegie Mellon. Cache Lab. Recitation 7: Oct 11 th, 2016

printf( Please enter another number: ); scanf( %d, &num2);

CS 470 Operating Systems Spring 2013 Shell Project

Homework 1 Due Monday April 24, 2017, 11 PM

C++ Optimization Activity

Today s Learning Objectives

Introduction to Supercomputing

EE 109 Lab 8a Conversion Experience

Assignment 1. CSI Programming Practice, Fall 2011

Working with Shell Scripting. Daniel Balagué

COMP1917: 09 Arrays and Strings

Exercise 1.1 Hello world

Lab 5 - Linked Lists Git Tag: Lab5Submission

Exercise Session 2 Systems Programming and Computer Architecture

CMPE 655 Fall 2016 Assignment 2: Parallel Implementation of a Ray Tracer

QUIZ Friends class Y;

Testing. Topics. Types of Testing. Types of Testing

Lab 8: Ordered Search Results

The print queue was too long. The print queue is always too long shortly before assignments are due. Print your documentation

CS 610: Intermediate Programming: C/C++ Making Programs General An Introduction to Linked Lists

Final Exam 1 /12 2 /12 3 /10 4 /7 5 /4 6 /10 7 /8 8 /9 9 /8 10 /11 11 /8 12 /10 13 /9 14 /13 15 /10 16 /10 17 /12. Faculty of Computer Science

CSE 351, Spring 2010 Lab 7: Writing a Dynamic Storage Allocator Due: Thursday May 27, 11:59PM

EECE.2160: ECE Application Programming

Lab 03 - x86-64: atoi

Warm-up sheet: Programming in C

Lab 2: Threads and Processes

QUIZ. What is wrong with this code that uses default arguments?

Macros and Preprocessor. CGS 3460, Lecture 39 Apr 17, 2006 Hen-I Yang

Assignment 5: Priority Queue

Chris' Makefile Tutorial

Programming Assignment 2 (PA2) - DraggingEmoji & ShortLongWords

Laboratory 1 Semester 1 11/12

Exercise Session 2 Simon Gerber

CS201: Lab #4 Writing a Dynamic Storage Allocator

Processor. Lecture #2 Number Rep & Intro to C classic components of all computers Control Datapath Memory Input Output

Decaf PP2: Syntax Analysis

A Fast Review of C Essentials Part I

York University Faculty Science and Engineering Fall 2008

Lab 4: Tracery Recursion in C with Linked Lists

C for C++ Programmers

Little Motivation Outline Introduction OpenMP Architecture Working with OpenMP Future of OpenMP End. OpenMP. Amasis Brauch German University in Cairo

Carleton University Department of Systems and Computer Engineering SYSC Foundations of Imperative Programming - Winter 2012

1. Overview This project will help you understand address spaces and virtual memory management.

Programming with MPI

EE109 Lab Need for Speed

Lecture Topics. Administrivia

Cache Lab Implementation and Blocking

Transcription:

Programming Assignment Multi-Threading and Debugging 2 Due Date: Friday, June 1 @ 11:59 pm PAMT2 Assignment Overview The purpose of this mini-assignment is to continue your introduction to parallel programming and multithreading. It will cover aspects of implementation, as well as the benefits and tradeoffs involved. You will again be provided with skeleton code, and this time you will fill in the functionality where necessary to determine whether a large number is prime or not. This will be done both in parallel over many threads simultaneously and sequentially in one. The program will also record and display the execution time of the calculations using both methods, allowing you to see the relative performance of each. NOTE: Once again, due to CPU-intensive nature of this multi-threading assignment, we are developing and testing the multi-threaded programming assignment on the workstations (preferred) or ieng6. You can also develop on the pi-cluster, but the execution times will be much slower. Debug2 Assignment Overview You will also get to practice your debugging skills again. We have written a program that will start a command line tic-tac-toe game. We think it s close to working, but we didn't have time to debug it. It's now your job to help us track down the bugs and fix them so we can get it to work. You should reference your notes on static vs. global to help you finish this assignment. The debugging exercise must be completed on pi-cluster. To summarize: 1. PAMT2 must be developed, executed, and turned in with your cs30x account on the workstations in the lab (preferred) or ieng6.ucsd.edu or pi-cluster remotely. 2. Debug2 must be debugged, executed, and turned in with your cs30x account on pi-cluster.ucsd.edu. PAMT2 Grading README: 10 points - See PAMT2 README File section. Compiling: 10 points - Using our Makefile; no warnings. If what you turn in does not compile with the given Makefile, you will receive 0 points for this assignment. NO EXCEPTIONS! Correctness: 40 points - Includes both abnormal and normal output, both to the correct destination (stderr vs stdout). Debug2 Grading README: 30 points - See Debug2 README File section. Correctness: 10 points NOTE: If what you turn in does not compile with given Makefile, you will receive 0 points for this assignment.

PAMT2 Overview Once again, all functions for pamt2 are written in C. Your job is to fill in the missing functionality. Gathering Starter Files for PAMT2: $ cd ~ $ mkdir pamt2 $ cp ~/../public/pamt2starterfiles/* ~/pamt2/ You should now have a directory named pamt2. This will contain the starter files for the project, listed below. You are responsible for filling in the code in numoffactors.c and parallel_numoffactors.c. Starter files provided: parallel_numoffactors.c pamt2.h numoffactors.c Makefile main.c PAMT2 Sample Output This program takes a list of long long integers (64 bit numbers, up to about 9 quintillion in decimal) and displays information on whether each number is prime and how long it took to determine that. Below are a few examples on one of the ieng6 servers and B240 workstation (bold indicates user input): [cs30xzzz@ieng6-203]:pamt2$./pamt2 8081 246813607 Calculating number of factors for 8081 with sequential numoffactors() [be patient with large values] 8081 is prime Number of factors: 2 Completed in 0.000115 sec Calculating number of factors for 8081 with parallel numoffactors() [be less patient] Num of threads = 8 8081 is prime Number of factors: 2 Completed in 0.004275 sec *** numoffactors Speed-up: 0.026795 *** Calculating number of factors for 246813607 with sequential numoffactors() [be patient with large values] 246813607 is prime Number of factors: 2 Completed in 3.411575 sec Calculating number of factors for 246813607 with parallel numoffactors() [be less patient]

Num of threads = 8 246813607 is prime Number of factors: 2 Completed in 0.651391 sec *** numoffactors Speed-up: 5.237366 *** [cs30xzzz@its-cseb240-01]:pamt2$./pamt2 790738119649411319 8589934592 Skipping 790738119649411319 num should be less than or equal to 8589934592 Calculating number of factors for 8589934592 with sequential numoffactors() [be patient with large values] 8589934592 is not prime Number of factors: 34 Completed in 70.999416 sec Calculating number of factors for 8589934592 with parallel numoffactors() [be less patient] Num of threads = 8 8589934592 is not prime Number of factors: 34 Completed in 15.083121 sec *** numoffactors Speed-up: 4.707210 *** [cs30xzzz@ its-cseb240-01]:pamt2$./pamt2 420420 8589934590 Calculating number of factors for 420420 with sequential numoffactors() [be patient with large values] 420420 is not prime Number of factors: 144 Completed in 0.003668 sec Calculating number of factors for 420420 with parallel numoffactors() [be less patient] Num of threads = 8 420420 is not prime Number of factors: 144 Completed in 0.000728 sec *** numoffactors Speed-up: 5.038831 *** Calculating number of factors for 8589934590 with sequential numoffactors()

[be patient with large values] 8589934590 is not prime Number of factors: 64 Completed in 69.215721 sec Calculating number of factors for 8589934590 with parallel numoffactors() [be less patient] Num of threads = 8 8589934590 is not prime Number of factors: 64 Completed in 13.965570 sec *** numoffactors Speed-up: 4.956169 *** Note that the first group of results for each number is for sequential mode (checking each possible factor of the number in sequence in a single thread), while the second group of results is for parallel mode. Like last time, the speedup is the factor by which parallel computation of the result is faster than sequential. A speedup of 1 would mean that both methods are about equally fast, while a speedup of less than 1 would indicate that the sequential mode is better (the overhead of forking and joining threads can dominate small problems), and a speedup of greater than 1 would indicate that the parallel mode is better. Your elapsed times and speed-ups might not be exactly the same as the sample output, but it should look reasonable and justifiable. The number of factors calculated need to be the same between the sequential and parallel versions for any given number. By most definitions, prime numbers are natural numbers greater than 1 that has no positive divisors other than 1 and itself. So negative numbers input will result in 0 factors and are not prime. C routines: int main( int argc, char * argv[] ); long long numoffactors( long long n, long long lo, long long hi ); long long parallel_numoffactors( long long n, long long lo, long long hi ); PAMT2 Modules main.c int main( int argc, char * argv[] ); The driver of the program. For each number entered on the command line, main() calls gettimeofday() to get the start time, and then calls numoffactors() to run the calculations sequentially. Upon return, gettimeofday() is called again to get the end time. The time difference is then calculated and the results of the sequential run are printed to stdout. Everything up to this point is given to you in the starter code. It then does the same thing with parallel_numoffactors(). Note: There is a comment marked TODO in main.c that shows you where you should make additions/changes. You do not need to (and in fact should not) make changes to main.c anywhere except at this point. You should remove the return 0 once parallel_numoffactors() has been implemented.

numoffactors.c long long numoffactors( long long n, long long lo, long long hi ); To implement numoffactors(), use the algorithm provided in the header. parallel_numoffactors.c long long parallel_numoffactors( long long n, long long lo, long long hi ); To implement parallel_numoffactors(), copy over your working sequential code from numoffactors.c. Then using what you learned in pamt1, create a OMP pragma to parallelize the loop you created for the third part of the algorithm. Remember to comment out the return 0 on line 78 in main.c when you are ready to test your parallel_numoffactors. PAMT2 README File Along with your source code, you will be turning in a README (use all caps and no file extension for example, the file is README and not README.txt) file with every assignment. Use vi/vim to edit this file! Your README file for this and all assignments should contain: High level description of what your program does. How to compile it (be more specific than: just typing make --i.e., what directory should you be in?, where should the source files be?, etc.). How to run it (give an example). An example of normal output and where that normal output goes (stdout or a file or???). An example of abnormal/error output and where that error output goes (stderr usually). How you tested your program (what test values you used to test normal and error states) showing your tests covered all parts of your code (test coverage). (Be more specific than diff ing your output with the solution output--i.e., what are some specific test cases you tried?, what different types of cases did you test?, etc.) Anything else that you would want/need to communicate with someone who has not read the assignment write-up but may want to compile and run your program. Answers to questions (if there are any). Questions to Answer in the README 1. Try running pamt2 on a fairly large prime number 4294967291. You should see that the sequential version takes much longer time than the parallel version. Try running pamt2 on a fairly small non-prime number 8888. You should see that the sequential version takes much shorter time than the parallel version. For this program, does it matter if the number entered is prime or non-prime as far as the running time of the program is concerned? Why? 2. Try running pamt2 with a fairly large number (like 429496777) on one of the workstations, on ieng6, and recompile and run on one of the pi-cluster nodes. Which is more important in general: the overall speed-up gain by parallelizing or the number of threads available to parallelize or the time it takes to complete the sequential and parallel versions? Why? [Warning! This can take a fairly long time on a pi-cluster node.] 3. At about what value is the break-even point - where generally values larger than this break-even point the parallel version is faster on one of the workstations, on one of the ieng6 servers, and on a pi-cluster node?

Debugging Exercise 2 Overview The purpose of this program is to find the frequencies of words that occur within a given text file. The main() function is written in C, and it will run the game using various helper functions. We provide all of the code to you, but the code doesn't quite compile or work as it should. It is up to you to track down the bugs and fix them. There are a total of 8 bugs (2 compile-time bugs, 6 run-time bugs) in the source code. You are required to record ALL of the bugs we placed and the solution for each bug. See the section on Debug2 README File for more details. You DO NOT need to modify any file/function headers. Gathering Starter Files for Debug2: For debug2 (the debugging exercise), you will develop on pi-cluster as you do for most programming assignments. However, we will provide you with the buggy code. Simply go to your home directory and copy the whole folder to your home directory: $ cd ~ $ cp -r ~/../public/debug2. This will provide you with all of the buggy source code. All you have to do is fix the code and detail in a README file exactly what fixes you had to make to get this code to work properly. Include: Effects of the bug. What signaled to you that this bug exists? This can be error messages for compiler errors, weird behavior for runtime errors, etc. The line number(s) of the fix(es). (These may change as you fix more bugs, so it's fine if the numbers aren't exact) What the line(s) looked like before and after your fix(es). A short explanation (1-2 sentences is fine) of your reasoning behind each fix and how you debugged the problem. Keep in mind that each bug fix should only modify at most three (3) lines of code. These lines may be separated by other lines, but if you can logically consider them as part of the same error, they should be documented together. However, if you find yourself thinking of a fix that changes more than this number of lines, either the bug is not in those lines, or your fix can be written more concisely. Another thing to note (if you aren't already doing this): if, while trying to fix a bug, you notice some code is definitely wrong but fixing it does not get rid of the bug -- make note of your fix for later, but work on solving the current bug first. Since you need to document the effects of each bug, you should undo this early fix until you find the actual fix to the current bug you are encountering. Debug2 Sample Output The program takes no arguments from the command line: $./freqs Below are a few examples (bold indicates user input):

If the user didn't pass in the correct format, an error message is printed. [cs30xyz@pi-cluster-042]:debug2$./freqs Please supply a file name. [cs30xyz@pi-cluster-042]:debug2$ There are sample files in the files/ directory for you to play with. It would also be beneficial for you to test with /usr/share/dict/words as a stress test. It may also be helpful for you to create your own test files. [cs30xyz@pi-cluster-042]:debug2$./freqs files/avengers_ultron Commands are: freqs [word1, word2,...] Print the frequency of a word or the sum of frequencies of many words. display Display the entire frequencies table. help Display this message. Please enter a command: freqs Ultron Sum of frequencies of the words: 37 Please enter a command: freqs Stark Sum of frequencies of the words: 32 Please enter a command: freqs Thanos Sum of frequencies of the words: 0 Please enter a command: ^D [cs30xyz@pi-cluster-042]:debug2$ C routines: int main( int argc, char * argv[] ); void handleuserinput( struct Freq * wordslist, unsigned int numwords ); int parsecmd( const char * const cmdstring, const char * const commands[] ); int parsefile( struct Freq ** wordslistptr, FILE * infile ); void * bsearchd( const void * key, const void * base, size_t nmemb, size_t size, void * def, int (*compar)( const void *, const void * ) ); Assembly routines: unsigned int accumulatewordcount( unsigned int currcount, struct Freq * wordslist, int numwords, char * word ); int comparefreqword( const void * f1, const void * f2 );

Debug2 C Modules freqs.c int main( int argc, char * argv[] ); The main driver of this program. This will parse the user inputted file name, read the file with parsefile, and allow the user to interactively search with handleuserinput. Finally, it will free the entire frequencies table. Reasons for error: File name argument not given. File could not be opened. parsefile encountered an error. EXIT_FAILURE if an error encountered, otherwise EXIT_SUCCESS. parsefile.c int parsefile( struct Freq ** wordslistptr, FILE * infile ); This function will read in the file pointed to by infile and store unique words (case-sensitive) from the file in individual struct Freq entries in a dynamically growing, sorted array of struct Freq. Finally, it will update wordslistptr to point to the memory space dynamically allocated for that array, and return the number of unique words it found. Reasons for error: Memory limit exceeded. The number of unique words (i.e. the size of the array), or -1 if an error was encountered. handleuserinput.c void handleuserinput( struct Freq * wordslist, unsigned int numwords ); This function constantly prompts the user to enter a command for the interactive search feature. It will parse the command entered by the user, and execute that functionality if the command is valid. If the freqs command was entered, we will loop through all of the words following that command and compute the sum of the frequencies of those words as found in the array pointed to by wordslist using accumulatewordcount. If the display command was entered, we will print out all of the words in each struct Freq and its corresponding frequency. None. parsecmd.c int parsecmd( const char * const cmdstring, const char * const commands[] ); This function checks to see if the cmdstring is in the commands array. The index of the cmdstring in the commands array, or -1 if not found.

bsearchd.c void * bsearchd( const void * key, const void * base, size_t nmemb, size_t size, void * def, int (*compar)( const void *, const void * ) ); This function is a wrapper around the bsearch() standard library function, which does a binary search on a sorted array for the given key. See man -s3 bsearch for more details. The bsearchd() wrapper will return a pointer to the array element that matches the given key. It also defines an extra parameter, def, which is a default pointer that should be returned if an element matching key could not be found in the array. Note that both the key and def parameters must be pointing to objects of the same type as the ones that are stored in the array. A pointer to the element in the array that matches the key, or the def default pointer if no such element exists in the array. Debug2 Assembly Modules accumulatewordcount.s unsigned int accumulatewordcount( unsigned int currcount, struct Freq * wordslist, int numwords, char * word ); This function will add the frequency of a given word to a current count. If the word does not appear in the wordslist, the frequency of the word is assumed to be zero. The accumulated count: currcount + the frequency of word in the wordslist. comprefreqword.s int comparefreqword( const void * f1, const void * f2 ); This function compares two struct Freqs based on their word members. Will order the structs in based on the alphabetical order of their words. -1 if f1->word is alphabetically earlier than f2->word 0 if f1->word is the same string as f2->word 1 if f1->word is alphabetically later than f2->word

Debug2 README File For the debugging assignments only, you do not have to include the usual high level description, how tested, etc. in your README file. You will, however, have to list the compilation error you encountered and the fix you made to correct the error. You will also have to solve several logic errors. Again, for each problem, describe: Effects of the bug. What signaled to you that this bug exists? This can be error messages for compiler errors, weird behavior for runtime errors, etc. The line number(s) of the fix(es). (These may change as you fix more bugs, so it's fine if the numbers aren't exact) What the line(s) looked like before and after your fix(es). A short explanation (1-2 sentences is fine) of your reasoning behind each fix and how you debugged the problem. As a guideline, there should be 2 compilation errors and 6 functionality problems. Make sure you locate all of them! (Note: When we say there is 1 compilation error, we mean that there is one fix you'll have to make, not that there is one error printed to the screen. In general, you should not have to modify more than 3 lines of code per fix). If you happen to find more than 8 errors, document all of them anyway. It is most likely that you are considering one error as many different errors. We will grade you based on what fixes you make - not the number of errors you find. In other words, you will not lose points for documenting extra errors. Turn-in Instructions Complete Turnin - due Friday night, June 1 @ 11:59 pm Once you have checked your output, compiled, executed your code, and finished your README files, you are ready to turn in your assignments. How to Turn in an Assignment Use the following scripts to submit your assignments before the due date as follows: PAMT2: In your cs30x account on the lab workstations or the pi-cluster or ieng6. $ ~/../public/bin/cse30turnin pamt2 Debug2: In your cs30x account on pi-cluster. You will not be able to turn-in debug2 on ieng6 or the lab workstations. $ ~/../public/bin/cse30turnin debug2