From 71a6eeb31951ccf4834f11463c63699d6cc5fb23 Mon Sep 17 00:00:00 2001 From: "lisa.pizzo" Date: Thu, 4 Dec 2025 11:47:57 +0100 Subject: [PATCH] Delete Sheet5/mainEx2.cpp --- Sheet5/mainEx2.cpp | 86 ---------------------------------------------- 1 file changed, 86 deletions(-) delete mode 100644 Sheet5/mainEx2.cpp diff --git a/Sheet5/mainEx2.cpp b/Sheet5/mainEx2.cpp deleted file mode 100644 index 07633d4..0000000 --- a/Sheet5/mainEx2.cpp +++ /dev/null @@ -1,86 +0,0 @@ -//HOW TO RUN IT ON MY TERMINAL (MAC) -//export PATH="/opt/homebrew/opt/llvm/bin:$PATH" -//export CPPFLAGS="-I/opt/homebrew/opt/libomp/include" -//export LDFLAGS="-L/opt/homebrew/opt/libomp/lib" -//clang++ -std=c++17 -O2 -Xpreprocessor -fopenmp $CPPFLAGS mainEx2.cpp $LDFLAGS -lomp -o Ex2 -//./Ex2 - -#include -#include -#include -#include -#include -#include //for parallelization functions - -using namespace std; - -// compute arithmetic, geometric, harmonic means (safe geometric mean) -void computeMeansVector(const vector &v, double &arith, double &geom, double &harm) { - int n = v.size(); - double sum = 0.0, logSum = 0.0, recSum = 0.0; - - for (int x : v) { - sum += x; - logSum += log(x); // accumulate logarithms instead of multiplying - recSum += 1.0 / x; - } - arith = sum / n; - geom = exp(logSum / n); // geometric mean using exponent of average log - harm = n / recSum; -} - -// compute standard deviation -double computeStdDev(const vector &v, double mean) { - double sumSq = 0.0; - for (int x : v) { - sumSq += (x - mean) * (x - mean); - } - return sqrt(sumSq / v.size()); -} - -int main() { - vector v; - ifstream fin("data_1.txt"); //opens data for reading - int x; - while (fin >> x) { - v.push_back(x); - } - double t_start = omp_get_wtime(); - - // OpenMP threads check - int nthreads = 0; - #pragma omp parallel - { - int th_id = omp_get_thread_num(); - #pragma omp critical - { - cout << "Hello from thread " << th_id << endl; - } - #pragma omp master - nthreads = omp_get_num_threads(); - } - cout << "Total OpenMP threads used: " << nthreads << endl; - - int minVal = *min_element(v.begin(), v.end()); - int maxVal = *max_element(v.begin(), v.end()); - - double arith, geom, harm; - computeMeansVector(v, arith, geom, harm); - - double stddev = computeStdDev(v, arith); - - ofstream fout("out_1.txt"); - fout << "Min: " << minVal << "\nMax: " << maxVal - << "\nArithmetic mean: " << arith - << "\nGeometric mean: " << geom - << "\nHarmonic mean: " << harm - << "\nStandard deviation: " << stddev << "\n"; - - cout << "Min: " << minVal << "\nMax: " << maxVal - << "\nArithmetic mean: " << arith - << "\nGeometric mean: " << geom - << "\nHarmonic mean: " << harm - << "\nStandard deviation: " << stddev << endl; - - cout << "Elapsed time (s): " << omp_get_wtime() - t_start << endl; -}