From 24870324f8d4e1219c2a0ad61609ce59a10e491857024360d78f15b9fb106fe0 Mon Sep 17 00:00:00 2001 From: OkunElya Date: Thu, 29 Oct 2026 22:06:26 +1000 Subject: [PATCH] prettify, add clangd for zed --- .clangd | 2 ++ src/main.cpp | 16 +++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 .clangd diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..dee1bc7 --- /dev/null +++ b/.clangd @@ -0,0 +1,2 @@ + CompileFlags: + Add: [-std=c++20, -fopenmp] diff --git a/src/main.cpp b/src/main.cpp index efec49e..d2d689b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,8 +9,8 @@ #include #define CHACHE_LINE 64 -//par - parallel -//rr - round-robin +// par - parallel +// rr - round-robin // Lab 1 unsigned sum(const unsigned *V, std::size_t n) { @@ -54,7 +54,7 @@ unsigned sum_par_rr(const unsigned *V, std::size_t n) { return acc; } -//just a different way of allocation. seems simialr in speed +// just a different way of allocation. seems simialr in speed unsigned sum_par_rr_no_cache(const unsigned *V, std::size_t n) { unsigned acc = 0; unsigned *partial_sums = @@ -77,14 +77,16 @@ unsigned sum_par_rr_no_cache(const unsigned *V, std::size_t n) { return acc; } - +// lab 3 unsigned sum_loc_cpp(const unsigned *V, std::size_t n) { unsigned T = std::thread::hardware_concurrency(); - struct alignas(std::hardware_destructive_interference_size) p_t {//destructive as we want to minimize the distructive effect of cache interference + struct alignas(std::hardware_destructive_interference_size) + p_t { // destructive as we want to minimize the distructive effect of + // cache interference unsigned v; }; auto p = std::make_unique(T); - auto worker_proc = [V, n, T, &p](unsigned t) { + auto worker_proc = [V, n, T, &p](const unsigned t) { size_t s = n / T, b = n % T; if (t < b) b = ++s * t; @@ -114,7 +116,7 @@ unsigned sum_loc_cpp(const unsigned *V, std::size_t n) { int main(int argc, char **argv) { - std::size_t n = 1u << 29; + std::size_t n = 1u << 28; auto data = std::make_unique(n); #pragma omp parallel for for (std::size_t i = 0; i < n; ++i) {