Coder Social home page Coder Social logo

cop4520-assignment-3's Introduction

Problem 1

Execution

To compile the program, run the following command in the directory of the repo:

g++ -O2 -o problem1 problem1.cpp

In order to run the program, use the command:

./problem1

Approach

Since each operation was relatively short-lived, I opted to lock the entire linked list every time an operation is performed. This gives decent performance; the program runs in around 2.8 seconds on my machine.

Experimental evaluation

I ran the program 4 times (output available in the files named problem1-output.X.txt; warning: the files are around 40 MB each, might crash some text editors), and checked that the number of thank yous matches the number of presents in each test case.

Problem 2

Execution

To compile the program, run the following command in the directory of the repo:

g++ -O2 -o problem2 problem2.cpp

In order to run the program, use the command:

./problem2

Approach

The analysis is performed in a single thread, separate from the sensors. The analysis for each hour runs in O(nm) where n is the number of readings performed per hour, and m is the number of sensors. Each sensor running in its own thread produces readings in a loop, where for each reading, the sensor allocates a new node and appends it to a concurrent linked list that is only appended to by it, and only read from by the main analysis thread. All the operations performed in the sensor threads are lockless and performed using atomics, ensuring that sensors will have guaranteed progress. The analysis thread may occasionally spin when reading data, but that's okay since the analysis isn't time critical like the sensors are.

Since each sensor has a separate linked list, we only need to ensure that there are no race conditions between each individual sensor and the analysis thread. Since the analysis only advances the head once there is at least 60 minutes' worth of data in the linked list to analyze, there is no danger of race conditions.

Experimental evaluation

I ran the program 4 times (output available in the files named problem2-output.X.txt), and manually went through to check if the output looks valid, and confirmed that it is.

cop4520-assignment-3's People

Contributors

brianush1 avatar

Watchers

 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.