add assignment
This commit is contained in:
parent
f6d401f865
commit
231275b325
5 changed files with 250 additions and 0 deletions
143
assignments/01/ASSIGNMENT.md
Normal file
143
assignments/01/ASSIGNMENT.md
Normal file
|
@ -0,0 +1,143 @@
|
||||||
|
## Introduction
|
||||||
|
|
||||||
|
The purpose of this assignment is to become familiar with Pthreads and OpenMP by parallelizing a common algorithm in data mining: Linear classification with squared loss.
|
||||||
|
|
||||||
|
## Linear classification
|
||||||
|
|
||||||
|
The algorithm is described here.
|
||||||
|
|
||||||
|
You need to write two programs, called **lc_pthreads** and **lc_openmp**. Each program will accept four parameters as input: a filename of data points, a filename of data labels, number of outer iterations, and number of threads. Your programs should read in the data, run the classification algorithm, print your classification model loss to the standard output after each outer iteration (explained in the algorithm), and finally print the time taken by your program to the standard output at the end.
|
||||||
|
|
||||||
|
## Dataset
|
||||||
|
|
||||||
|
The dataset you'll use in this project is derived from the MNIST dataset. Since you'll perform binary classification in this project, the dataset here corresponds to pixel values of 28X28 images of handwritten digits corresponding to digits '1' and '7'. In the label file provided, the label corresponding to digit '1' is 1, while for '7', it is -1.
|
||||||
|
|
||||||
|
## Input/Output Formats
|
||||||
|
|
||||||
|
Each program will take as input two files (the list of data points, and the list of labels).
|
||||||
|
|
||||||
|
The input file with data points contains N+1 lines. The first line contains two space-separated integers: the number of data points (N), and the dimensionality of each data point (D). The following N lines each contain D space-separated integerss which represent the coordinates of the current data point. For example, an input with four two-dimensional data points would be stored in a file as:
|
||||||
|
|
||||||
|
```
|
||||||
|
4 2
|
||||||
|
1 1
|
||||||
|
1 2
|
||||||
|
3 4
|
||||||
|
3 2
|
||||||
|
```
|
||||||
|
|
||||||
|
The input file with class labels contains N+1 lines. The first line contains the number of data points (N). The following N lines each contains one integer each, the class label of each data-point. For example, an input with four data points would be stored in a file as:
|
||||||
|
|
||||||
|
```
|
||||||
|
4
|
||||||
|
1
|
||||||
|
-1
|
||||||
|
1
|
||||||
|
-1
|
||||||
|
```
|
||||||
|
|
||||||
|
Your program must also print the execution time to standard output. You should use a high-precision, monotonic, wall-clock timer and also omit the time spent reading the files. We recommend the function clock_gettime() when on a Linux system. You will be graded on a Linux system. Here is a function that you may use for timing:
|
||||||
|
|
||||||
|
```c
|
||||||
|
/* Gives us high-resolution timers. */
|
||||||
|
#define _POSIX_C_SOURCE 199309L
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Return the number of seconds since an unspecified time (e.g., Unix
|
||||||
|
* epoch). This is accomplished with a high-resolution monotonic timer,
|
||||||
|
* suitable for performance timing.
|
||||||
|
*
|
||||||
|
* @return The number of seconds.
|
||||||
|
*/
|
||||||
|
static inline double monotonic_seconds()
|
||||||
|
{
|
||||||
|
struct timespec ts;
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
|
return ts.tv_sec + ts.tv_nsec * 1e-9;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
You should use the following function to output your execution time:
|
||||||
|
|
||||||
|
```c
|
||||||
|
/**
|
||||||
|
* @brief Output the seconds elapsed while execution.
|
||||||
|
*
|
||||||
|
* @param seconds Seconds spent on execution, excluding IO.
|
||||||
|
*/
|
||||||
|
static void print_time(double const seconds)
|
||||||
|
{
|
||||||
|
printf("Execution time: %0.04fs\n", seconds);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Failure to follow any of these output instructions will result in significant loss of points.
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
Data files are also provided on phi0{1..8}.cselabs.umn.edu at /export/scratch/CSCI5451_F23/assignment-1/dataset. The data file is named MNIST_data.csv and the label file is named MNIST_label.csv.
|
||||||
|
|
||||||
|
**You should only run your code on one of the phi machines.** Use the last digit of your student ID to select the machine. For example, if your student ID is "1234567", use phi07. If your ID ends with 0 or 9, use the second-to-last digit.
|
||||||
|
|
||||||
|
We also provide one small test case (two-dimensional dataset) you can use to verify the correctness of your code: The corresponding files are small_data.csv and small_label.csv. Coordinate descent over this dataset should be able to converge in less than 10 iterations and the resultant w vector should be something like [0.394713 0.550215].
|
||||||
|
|
||||||
|
Remember that the TA will be evaluating your data with a different data sets than those provided for testing.
|
||||||
|
|
||||||
|
## What you need to turn in
|
||||||
|
|
||||||
|
1. The source code of your programs.
|
||||||
|
2. A short report including the following two parts:
|
||||||
|
1. A short description of how you went about parallelizing the classification algorithm. You should include how you decomposed the problem and why, i.e., what were the tasks being parallelized.
|
||||||
|
2. Timing results for 1, 2, 4, 8, and 16 threads for the classification. You should include results with outer iterations set to 10.
|
||||||
|
|
||||||
|
Do NOT include the test files; TA will have their own test files for grading. You will lose significant points for including test files.
|
||||||
|
|
||||||
|
Additional specifications related to assignment submission
|
||||||
|
|
||||||
|
- A makefile must be provided to compile and generate the two executables. The executables should be named:
|
||||||
|
|
||||||
|
- lc_pthreads
|
||||||
|
- lc_openmp
|
||||||
|
|
||||||
|
- Program invocation: Your programs should take as an argument the input file containing data points, file containing labels, the number of outer iterations, and the number of threads to be used for parallel execution. For example, with ten outer iterations and two threads, each of the programs would be invoked as follows:
|
||||||
|
|
||||||
|
```
|
||||||
|
./lc_pthreads /export/scratch/CSCI5451-F23/assignment-1/data.csv /export/scratch/CSCI5451-F23/assignment-1/data.label 10 2
|
||||||
|
./lc_openmp /export/scratch/CSCI5451-F23/assignment-1/data.csv /export/scratch/CSCI5451-F23/assignment-1/data.label 10 2
|
||||||
|
```
|
||||||
|
|
||||||
|
- All files (code + report) MUST be in a single directory and the directory's name MUST be your UMN login ID (e.g., your UMN email or Moodle username). Your submission directory MUST include at least the following files (other auxiliary files may also be included):
|
||||||
|
|
||||||
|
```
|
||||||
|
<UMN ID>/lc_pthreads.c
|
||||||
|
<UMN ID>/lc_openmp.c
|
||||||
|
<UMN ID>/Makefile
|
||||||
|
<UMN ID>/report.pdf
|
||||||
|
```
|
||||||
|
|
||||||
|
If you choose to code in C++, then replace the .c suffixes with .cpp or .cc.
|
||||||
|
|
||||||
|
- Submission MUST be in .tar.gz
|
||||||
|
- The following sequence of commands should work on your submission file:
|
||||||
|
|
||||||
|
```
|
||||||
|
tar xzvf <UMN ID>.tar.gz
|
||||||
|
cd <UMN ID>
|
||||||
|
make
|
||||||
|
ls -ld lc_pthreads
|
||||||
|
ls -ld lc_openmp
|
||||||
|
```
|
||||||
|
|
||||||
|
This ensures that your submission is packaged correctly, your directory is named correctly, your makefile works correctly, and your output executables are named correctly. If any of these does not work, modify it so that you do not lose points. The TAs can answer questions about correctly formatting your submission BEFORE the assignment is due. Do not expect them to answer questions the night it is due.
|
||||||
|
|
||||||
|
**Failure to follow any of these submission instructions will result in significant loss of points.**
|
||||||
|
|
||||||
|
## Evaluation criteria
|
||||||
|
|
||||||
|
The goal for this assignment is for you to become familiar with the APIs and not so much for developing the most efficient parallel program (this will be done later). As such, full points will be given to the programs that:
|
||||||
|
|
||||||
|
1. follows the assignment directions;
|
||||||
|
2. solve the problem correctly;
|
||||||
|
3. do so in parallel (i.e., sub-steps that can be parallelized are parallelized); and
|
||||||
|
4. achieves good speed-up.
|
1
assignments/01/rust/.gitignore
vendored
Normal file
1
assignments/01/rust/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
target
|
96
assignments/01/rust/Cargo.lock
generated
Normal file
96
assignments/01/rust/Cargo.lock
generated
Normal file
|
@ -0,0 +1,96 @@
|
||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "autocfg"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crossbeam-deque"
|
||||||
|
version = "0.8.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"crossbeam-epoch",
|
||||||
|
"crossbeam-utils",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crossbeam-epoch"
|
||||||
|
version = "0.9.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
"cfg-if",
|
||||||
|
"crossbeam-utils",
|
||||||
|
"memoffset",
|
||||||
|
"scopeguard",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crossbeam-utils"
|
||||||
|
version = "0.8.16"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "either"
|
||||||
|
version = "1.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memoffset"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rayon"
|
||||||
|
version = "1.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1"
|
||||||
|
dependencies = [
|
||||||
|
"either",
|
||||||
|
"rayon-core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rayon-core"
|
||||||
|
version = "1.12.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed"
|
||||||
|
dependencies = [
|
||||||
|
"crossbeam-deque",
|
||||||
|
"crossbeam-utils",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rust"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"rayon",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "scopeguard"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
7
assignments/01/rust/Cargo.toml
Normal file
7
assignments/01/rust/Cargo.toml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
[package]
|
||||||
|
name = "rust"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
rayon = "1.8.0"
|
3
assignments/01/rust/src/main.rs
Normal file
3
assignments/01/rust/src/main.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
fn main() {
|
||||||
|
println!("Hello, world!");
|
||||||
|
}
|
Loading…
Reference in a new issue