GithubHelp home page GithubHelp logo

andreas237 / cs5500_os_project2 Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 184 KB

The purpose of this project is to practice Pthread programming by solving various problems. The objectives of this project is to: 1. Get familiar with Pthread creation and termination. 2. Learn how to use mutexes and conditional variables in Pthread. 3. Learn how to design efficient solutions for mutual exclusion problems.

Makefile 1.75% C 84.13% Shell 1.80% Python 12.32%

cs5500_os_project2's Introduction

Project 2

Task 1

Given two character strings s1 and s2. Write a Pthread program to find out the number of substrings, in string s1, that is exactly the same as s2. For example, if number substring(s1, s2) implements the function, then you have number substring(‘‘abcdab", ‘‘ab") = 2, number substring(‘‘aaa", ‘‘a") = 3, and number substring(‘‘abac", ‘‘bc") = 0. The size of s1 and s2 (n1 and n2), as well as their data are the input by the user, via a file. Assume that n1 is at least twice as long as n2. Attached code substring sequential.c is a sequential solution of the problem. read_f() reads the two strings from a file named string.txt, and num_substring() calculates the number of substrings. Write a parallel program using Pthread based on this sequential solution.

Task 2

Use condition variables to solve a producer-consumer problem. Here we have two threads: one producer and one consumer. The producer reads characters one by one from a string stored in a file named message.txt, then writes sequentially these characters into a circular queue. Meanwhile, the consumer reads sequentially from the queue and prints them in the same order. Assume a buffer (queue) size of 6 characters. Write a Pthread program using condition variables.

Task 3

Find the implementation of Task 3 in task3/. Read attached code list-forming.c and modify the program to improve its performance. In this program there are num_threads threads. Each thread creates a data node and attaches it to a global list. This operation is repeated K times by each thread. The performance of this program is measured by the program runtime (in microsecond). Apparently, the operation of attaching a node to the global list needs to be protected by a lock and the time to acquire the lock contributes to the total run time. Try to modify the program in order to reduce the program runtime.

Task 3 Requirements

  1. Implement a modified version of list-forming.c and name it my_list-forming.c.
  2. Verify that your program achieves better performance than the original version by using different combinations of K and num_threads. Typical values of K could be 200, 400, 800,... Typical values of num threads could be 2, 4, 8, 16, 32, 64,... Draw diagrams to show the performance trend.
  3. In the report, explain your design and discuss the performance results.

Implementation Details

Tasks 1 and 2

Are each implemented in their own .h files. main.c runs both.

T

To compile on a GNU/Linux machine type make in the root directors.

  • .o files are generated in odir/
  • .h files are in include/

make clean removes .o files *~ core and the executable, exec_p2

Task 3

Is implemented on its own because due to the requirements in project2.pdf. See task3/, a Makefile is provided for simplicity. In order to generate results for plotting a bash script it provided. The data is written to task3/data.txt (thanks!). Python's matplotlib will graph the results.

cs5500_os_project2's People

Contributors

andreas237 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.