-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
603e1c5
commit aec2013
Showing
63 changed files
with
1,499 additions
and
1,973 deletions.
There are no files selected for viewing
Binary file modified
BIN
+142 KB
(100%)
60029 - Data Processing Systems/60029 - Data Processing Systems.pdf
Binary file not shown.
2 changes: 2 additions & 0 deletions
2
60029 - Data Processing Systems/60029 - Data Processing Systems.tex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...9 - Data Processing Systems/advanced_topics/code/partition_comparison/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
## What is this? | ||
[Tests](tests.cpp) & [benchmarks](benchmarks.cpp) for the partition algorithms discussed in the advanced topics lecture. | ||
|
||
## To build & Run | ||
```bash | ||
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release | ||
make -j -C build/ | ||
./build/Test | ||
./build/Benchmark | ||
./build/Examples | ||
``` |
100 changes: 59 additions & 41 deletions
100
60029 - Data Processing Systems/advanced_topics/code/partition_comparison/benchmarks.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,96 @@ | ||
#include "in_place_conditional.h" | ||
#include "in_place_predicated.h" | ||
#include "out_of_place_conditional.h" | ||
#include "out_of_place_predicated.h" | ||
#include "partitions/in_place_conditional.h" | ||
#include "partitions/in_place_predicated.h" | ||
#include "partitions/out_of_place_conditional.h" | ||
#include "partitions/out_of_place_predicated.h" | ||
|
||
#include <benchmark/benchmark.h> | ||
|
||
|
||
std::vector<int> ordered_ints(size_t n) { | ||
std::vector<int> vec; | ||
vec.reserve(n); | ||
for (auto i = 0; i < n; i++) vec.push_back(i); | ||
return vec; | ||
std::vector<int> vec; | ||
vec.reserve(n); | ||
for (auto i = 0; i < n; i++) | ||
vec.push_back(i); | ||
return vec; | ||
} | ||
|
||
std::vector<int> alternating_ints(size_t n) { | ||
std::vector<int> vec; | ||
vec.reserve(n); | ||
for (auto i = 0; i < n; i++) vec.push_back(i % 2 == 0 ? i : n - i); | ||
return vec; | ||
std::vector<int> vec; | ||
vec.reserve(n); | ||
for (auto i = 0; i < n; i++) | ||
vec.push_back(i % 2 == 0 ? i : n - i); | ||
return vec; | ||
} | ||
|
||
std::vector<int> random_ints(size_t n) { | ||
std::vector<int> vec; | ||
vec.reserve(n); | ||
srand(n); | ||
for (auto i = 0; i < n; i++) vec.push_back(rand()); | ||
return vec; | ||
std::vector<int> vec; | ||
vec.reserve(n); | ||
srand(n); | ||
for (auto i = 0; i < n; i++) | ||
vec.push_back(rand()); | ||
return vec; | ||
} | ||
|
||
// Benchmarking in place partitioning | ||
template<class T, size_t partition(std::vector<T>&, size_t, size_t), std::vector<T> generate(size_t)> | ||
template <class T, size_t partition(std::vector<T> &, size_t, size_t), | ||
std::vector<T> generate(size_t)> | ||
static void partition_in_place(benchmark::State &state) { | ||
for (auto _ : state) { | ||
state.PauseTiming(); | ||
std::vector<T> workload(generate(state.range(0))); | ||
std::vector<T> workload(generate(state.range(0))); | ||
state.ResumeTiming(); | ||
partition(workload, 0, workload.size()); | ||
benchmark::DoNotOptimize(workload); | ||
} | ||
} | ||
|
||
// Benchmarking out of place (no including alloc time for aux vector) | ||
template<class T, size_t partition(const std::vector<T>&, std::vector<T>&, size_t, size_t), std::vector<T> generate(size_t)> | ||
template <class T, | ||
size_t partition(const std::vector<T> &, std::vector<T> &, size_t, | ||
size_t), | ||
std::vector<T> generate(size_t)> | ||
static void partition_out_of_place(benchmark::State &state) { | ||
for (auto _ : state) { | ||
state.PauseTiming(); | ||
std::vector<T> workload(generate(state.range(0))); | ||
std::vector<T> aux(state.range(0)); | ||
std::vector<T> aux(state.range(0)); | ||
state.ResumeTiming(); | ||
partition(workload, aux, 0, workload.size()); | ||
benchmark::DoNotOptimize(aux); | ||
} | ||
} | ||
|
||
BENCHMARK(partition_in_place<int, hoare::partition, ordered_ints>)->Range(8 * 1024, 64 * 1024); | ||
BENCHMARK(partition_in_place<int, predicated_cracking::partition, ordered_ints>)->Range(8 * 1024, 64 * 1024); | ||
BENCHMARK(partition_out_of_place<int, out_of_place_cond::partition, ordered_ints>)->Range(8 * 1024, 64 * 1024); | ||
BENCHMARK(partition_out_of_place<int, out_of_place_pred::partition, ordered_ints>)->Range(8 * 1024, 64 * 1024); | ||
BENCHMARK(partition_in_place<int, hoare::partition, ordered_ints>) | ||
->Range(8 * 1024, 64 * 1024); | ||
BENCHMARK(partition_in_place<int, predicated_cracking::partition, ordered_ints>) | ||
->Range(8 * 1024, 64 * 1024); | ||
BENCHMARK( | ||
partition_out_of_place<int, out_of_place_cond::partition, ordered_ints>) | ||
->Range(8 * 1024, 64 * 1024); | ||
BENCHMARK( | ||
partition_out_of_place<int, out_of_place_pred::partition, ordered_ints>) | ||
->Range(8 * 1024, 64 * 1024); | ||
|
||
BENCHMARK(partition_in_place<int, hoare::partition, alternating_ints>)->Range(8 * 1024, 64 * 1024); | ||
BENCHMARK(partition_in_place<int, predicated_cracking::partition, alternating_ints>)->Range(8 * 1024, 64 * 1024); | ||
BENCHMARK(partition_out_of_place<int, out_of_place_cond::partition, alternating_ints>)->Range(8 * 1024, 64 * 1024); | ||
BENCHMARK(partition_out_of_place<int, out_of_place_pred::partition, alternating_ints>)->Range(8 * 1024, 64 * 1024); | ||
BENCHMARK(partition_in_place<int, hoare::partition, alternating_ints>) | ||
->Range(8 * 1024, 64 * 1024); | ||
BENCHMARK( | ||
partition_in_place<int, predicated_cracking::partition, alternating_ints>) | ||
->Range(8 * 1024, 64 * 1024); | ||
BENCHMARK( | ||
partition_out_of_place<int, out_of_place_cond::partition, alternating_ints>) | ||
->Range(8 * 1024, 64 * 1024); | ||
BENCHMARK( | ||
partition_out_of_place<int, out_of_place_pred::partition, alternating_ints>) | ||
->Range(8 * 1024, 64 * 1024); | ||
|
||
BENCHMARK(partition_in_place<int, hoare::partition, random_ints>)->Range(8 * 1024, 64 * 1024); | ||
BENCHMARK(partition_in_place<int, predicated_cracking::partition, random_ints>)->Range(8 * 1024, 64 * 1024); | ||
BENCHMARK(partition_out_of_place<int, out_of_place_cond::partition, random_ints>)->Range(8 * 1024, 64 * 1024); | ||
BENCHMARK(partition_out_of_place<int, out_of_place_pred::partition, random_ints>)->Range(8 * 1024, 64 * 1024); | ||
BENCHMARK(partition_in_place<int, hoare::partition, random_ints>) | ||
->Range(8 * 1024, 64 * 1024); | ||
BENCHMARK(partition_in_place<int, predicated_cracking::partition, random_ints>) | ||
->Range(8 * 1024, 64 * 1024); | ||
BENCHMARK( | ||
partition_out_of_place<int, out_of_place_cond::partition, random_ints>) | ||
->Range(8 * 1024, 64 * 1024); | ||
BENCHMARK( | ||
partition_out_of_place<int, out_of_place_pred::partition, random_ints>) | ||
->Range(8 * 1024, 64 * 1024); | ||
|
||
// To run this use: | ||
// cd partition_comparison | ||
// ```bash | ||
// cmake -S . -B build -DCMAKE_BUILD_TYPE=Release | ||
// make -j -C build/ | ||
// ./build/Partition-Benchmarks | ||
// ``` | ||
BENCHMARK_MAIN(); |
40 changes: 40 additions & 0 deletions
40
60029 - Data Processing Systems/advanced_topics/code/partition_comparison/examples.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "partitions/in_place_conditional.h" | ||
#include "partitions/in_place_predicated.h" | ||
#include "partitions/out_of_place_conditional.h" | ||
#include "partitions/out_of_place_predicated.h" | ||
#include <cstddef> | ||
#include <iostream> | ||
#include <vector> | ||
|
||
template <typename T> void print_vec(const std::vector<T> &v) { | ||
for (const auto &x : v) | ||
std::cout << x << ","; | ||
std::cout << std::endl; | ||
} | ||
|
||
void example_1() { | ||
std::vector<int> is = {2, 3, 12, 5, 6, 7, 34, 3, 2, 1, 3, 5, 7, 23}; | ||
// std::vector<int> is = { | ||
// 2, 1, 2, 6, 7, 34, 3, 5, 12, 3, 5, 7, 3, 23, | ||
// }; | ||
|
||
print_vec(is); | ||
auto part = predicated_cracking::partition(is, 0, is.size()); | ||
print_vec(is); | ||
std::cout << "partition at vec[" << part << "] = " << is[part] << std::endl; | ||
} | ||
|
||
void example_2() { | ||
std::vector<int> is = {7}; | ||
std::vector<int> ans(is.size()); | ||
|
||
print_vec(is); | ||
auto part = out_of_place_cond::partition(is, ans, 0, is.size()); | ||
print_vec(ans); | ||
std::cout << "partition at vec[" << part << "] = " << ans[part] << std::endl; | ||
} | ||
|
||
int main() { | ||
example_1(); | ||
example_2(); | ||
} |
Oops, something went wrong.