Compare commits

..

3 Commits

Author SHA1 Message Date
599b2b8dac Dev fix 2025-12-15 12:17:58 +01:00
560cc4a762 Counter fix and Logik-Deadlock Fix 2025-12-15 12:17:18 +01:00
0d6403a0b8 gitignore update 2025-12-15 11:51:08 +01:00
15 changed files with 10 additions and 2520 deletions

8
parallel2/.idea/.gitignore generated vendored
View File

@ -1,8 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

1
parallel2/.idea/.name generated
View File

@ -1 +0,0 @@
Uebung5

View File

@ -1,101 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="BackendCodeEditorSettings">
<option name="/Default/CodeStyle/CodeFormatting/CppClangFormat/EnableClangFormatSupport/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_ARGUMENT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_BINARY_EXPRESSIONS_CHAIN/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_CALLS_CHAIN/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_EXPRESSION/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_EXTENDS_LIST/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_FOR_STMT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_PARAMETER/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_TYPE_ARGUMENT/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_TYPE_PARAMETER/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTIPLE_DECLARATION/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_TERNARY/@EntryValue" value="ALIGN_ALL" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ANONYMOUS_METHOD_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_CLASS_DEFINITION/@EntryValue" value="1" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_DECLARATIONS/@EntryValue" value="0" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_FUNCTION_DECLARATION/@EntryValue" value="1" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_FUNCTION_DEFINITION/@EntryValue" value="1" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BREAK_TEMPLATE_DECLARATION/@EntryValue" value="LINE_BREAK" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/CASE_BLOCK_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/CONTINUOUS_LINE_INDENT/@EntryValue" value="Double" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_ACCESS_SPECIFIERS_FROM_CLASS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_CASE_FROM_SWITCH/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_CLASS_MEMBERS_FROM_ACCESS_SPECIFIERS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_COMMENT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_SIZE/@EntryValue" value="4" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_STYLE/@EntryValue" value="Space" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INITIALIZER_BRACES/@EntryValue" value="END_OF_LINE_NO_SPACE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INT_ALIGN_EQ/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INVOCABLE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_BLANK_LINES_IN_CODE/@EntryValue" value="2" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_BLANK_LINES_IN_DECLARATIONS/@EntryValue" value="2" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_USER_LINEBREAKS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/LINE_BREAK_AFTER_COLON_IN_MEMBER_INITIALIZER_LISTS/@EntryValue" value="ON_SINGLE_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/MEMBER_INITIALIZER_LIST_STYLE/@EntryValue" value="DO_NOT_CHANGE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/NAMESPACE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/NAMESPACE_INDENTATION/@EntryValue" value="All" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/OTHER_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_CATCH_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_ELSE_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_NAMESPACE_DEFINITIONS_ON_SAME_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_WHILE_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SIMPLE_BLOCK_STYLE/@EntryValue" value="DO_NOT_CHANGE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_CAST_EXPRESSION_PARENTHESES/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COLON_IN_BITFIELD_DECLARATOR/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COMMA_IN_TEMPLATE_ARGS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COMMA_IN_TEMPLATE_PARAMS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_EXTENDS_COLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_FOR_COLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_FOR_SEMICOLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_DATA_MEMBER/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_DATA_MEMBERS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_METHOD/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_PTR_IN_NESTED_DECLARATOR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_REF_IN_DATA_MEMBER/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_REF_IN_DATA_MEMBERS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_REF_IN_METHOD/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_UNARY_OPERATOR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_COLON_IN_BITFIELD_DECLARATOR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_EXTENDS_COLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_FOR_COLON/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_FOR_SEMICOLON/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_ABSTRACT_DECL/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_DATA_MEMBER/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_DATA_MEMBERS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_METHOD/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_ABSTRACT_DECL/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_DATA_MEMBER/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_DATA_MEMBERS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_METHOD/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_TEMPLATE_ARGS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BETWEEN_CLOSING_ANGLE_BRACKETS_IN_TEMPLATE_ARGS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_ARRAY_ACCESS_BRACKETS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_CAST_EXPRESSION_PARENTHESES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_DECLARATION_PARENTHESES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_BLOCKS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_INITIALIZER_BRACES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_METHOD_PARENTHESES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_INITIALIZER_BRACES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_TEMPLATE_ARGS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPECIAL_ELSE_IF_TREATMENT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TAB_WIDTH/@EntryValue" value="4" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TYPE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_BINARY_OPSIGN/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_DECLARATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_INVOCATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_ARGUMENTS_STYLE/@EntryValue" value="WRAP_IF_LONG" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_DECLARATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_DECLARATION_RPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_INVOCATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_INVOCATION_RPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_TERNARY_OPSIGNS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_PARAMETERS_STYLE/@EntryValue" value="WRAP_IF_LONG" type="string" />
<option name="/Default/CodeStyle/EditorConfig/EnableClangFormatSupport/@EntryValue" value="false" type="bool" />
</component>
</project>

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakePythonSetting">
<option name="pythonIntegrationState" value="YES" />
</component>
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/parallel2.iml" filepath="$PROJECT_DIR$/.idea/parallel2.iml" />
</modules>
</component>
</project>

View File

@ -1,2 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

View File

@ -1,15 +0,0 @@
cmake_minimum_required(VERSION 3.15)
project(Uebung5)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# OpenMP aktivieren
find_package(OpenMP REQUIRED)
if(OpenMP_CXX_FOUND)
message(STATUS "OpenMP found")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()
# Executable erstellen
add_executable(parallel2 main.cpp)

View File

@ -1,238 +0,0 @@
#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <chrono>
#include <cmath>
#include <omp.h>
// Matrizen erzeugen
void generateRandomMatrices(int n,
std::vector<std::vector<double>>& A,
std::vector<std::vector<double>>& B,
double min_val = 0.0,
double max_val = 10.0)
{
std::srand(static_cast<unsigned int>(std::time(nullptr)));
A.resize(n, std::vector<double>(n));
B.resize(n, std::vector<double>(n));
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
{
double r1 = static_cast<double>(std::rand()) / RAND_MAX;
double r2 = static_cast<double>(std::rand()) / RAND_MAX;
A[i][j] = min_val + r1 * (max_val - min_val);
B[i][j] = min_val + r2 * (max_val - min_val);
}
}
// Seriell
std::vector<std::vector<double>> matmul_serial(const std::vector<std::vector<double>>& A,
const std::vector<std::vector<double>>& B)
{
int n = A.size();
int m = B[0].size();
int p = B.size();
std::vector<std::vector<double>> C(n, std::vector<double>(m, 0.0));
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j)
for (int k = 0; k < p; ++k)
C[i][j] += A[i][k] * B[k][j];
return C;
}
// Parallele Zeilenzerlegung
std::vector<std::vector<double>> matmul_parallel_rows(const std::vector<std::vector<double>>& A,
const std::vector<std::vector<double>>& B,
int numThreads)
{
int n = A.size();
int m = B[0].size();
int p = B.size();
std::vector<std::vector<double>> C(n, std::vector<double>(m, 0.0));
#pragma omp parallel for num_threads(numThreads)
for (int i = 0; i < n; ++i)
{
std::vector<double> row(m, 0.0);
for (int j = 0; j < m; ++j)
{
double sum = 0.0;
for (int k = 0; k < p; ++k)
sum += A[i][k] * B[k][j]; //verhindert überschreibuung
row[j] = sum;
}
C[i] = row;
}
return C;
}
// Parallele Spaltenzerlegung
std::vector<std::vector<double>> matmul_parallel_cols(const std::vector<std::vector<double>>& A,
const std::vector<std::vector<double>>& B,
int numThreads)
{
int n = A.size();
int m = B[0].size();
int p = B.size();
std::vector<std::vector<double>> C(n, std::vector<double>(m, 0.0));
#pragma omp parallel for num_threads(numThreads)
for (int j = 0; j < m; ++j)
{
for (int i = 0; i < n; ++i)
{
double sum = 0.0;
for (int k = 0; k < p; ++k)
sum += A[i][k] * B[k][j]; //Zwischengepeichert
C[i][j] = sum;
}
}
return C;
}
// Blockzerlegung
std::vector<std::vector<double>> matmul_block(const std::vector<std::vector<double>>& A,
const std::vector<std::vector<double>>& B,
int blockSize,
int numThreads)
{
int n = A.size();
int m = B[0].size();
int p = B.size();
std::vector<std::vector<double>> C(n, std::vector<double>(m, 0.0));
#pragma omp parallel for collapse(2) num_threads(numThreads)
for (int ii = 0; ii < n; ii += blockSize)
for (int jj = 0; jj < m; jj += blockSize)
{
for (int i = ii; i < std::min(ii + blockSize, n); ++i)
for (int j = jj; j < std::min(jj + blockSize, m); ++j)
{
double sum = 0.0;
for (int k = 0; k < p; ++k)
sum += A[i][k] * B[k][j];
C[i][j] = sum;
}
}
return C;
}
// Matrix ausgeben
void printMatrix(const std::vector<std::vector<double>>& M, const std::string& name)
{
std::cout << name << " (" << M.size() << "x" << (M.empty() ? 0 : M[0].size()) << "):\n";
for (const auto& row : M)
{
for (double val : row)
std::cout << val << "\t";
std::cout << "\n";
}
std::cout << "\n";
}
//Matrix Vergleich (Komponentenweise)
bool compareMatrices(const std::vector<std::vector<double>>& A,
const std::vector<std::vector<double>>& B)
{
if (A.size() != B.size() || A[0].size() != B[0].size())
return false;
for (size_t i = 0; i < A.size(); ++i)
for (size_t j = 0; j < A[0].size(); ++j)
if (std::abs(A[i][j] - B[i][j]) > 1e-9)
return false;
return true;
}
int main()
{
int N = 4; // für Ausgabe kleiner Matrizen <5
int numThreads = omp_get_max_threads();
if (numThreads == 0) numThreads = 4;
std::vector<std::vector<double>> A, B;
generateRandomMatrices(N, A, B);
if (N < 5)
{
printMatrix(A, "Matrix A");
printMatrix(B, "Matrix B");
}
// Serielle Berechnung
auto start = std::chrono::steady_clock::now();
auto C_serial = matmul_serial(A, B);
auto end = std::chrono::steady_clock::now();
double timeSerial = std::chrono::duration<double>(end - start).count();
std::cout << "Seriell: " << timeSerial << " s\n";
if (N < 5)
printMatrix(C_serial, "C_serial");
// Zeilenparallel
start = std::chrono::steady_clock::now();
auto C_rows = matmul_parallel_rows(A, B, numThreads);
end = std::chrono::steady_clock::now();
double timeRows = std::chrono::duration<double>(end - start).count();
std::cout << "Parallel Zeilen: " << timeRows << " s | "
<< (compareMatrices(C_serial, C_rows) ? "Match" : "Mismatch") << "\n";
if (N < 5)
printMatrix(C_rows, "C_rows");
// Spaltenparallel
start = std::chrono::steady_clock::now();
auto C_cols = matmul_parallel_cols(A, B, numThreads);
end = std::chrono::steady_clock::now();
double timeCols = std::chrono::duration<double>(end - start).count();
std::cout << "Parallel Spalten: " << timeCols << " s | "
<< (compareMatrices(C_serial, C_cols) ? "Match" : "Mismatch") << "\n";
if (N < 5)
printMatrix(C_cols, "C_cols");
// Blockparallel
int blockSize = 2; // für kleine N passend
start = std::chrono::steady_clock::now();
auto C_block = matmul_block(A, B, blockSize, numThreads);
end = std::chrono::steady_clock::now();
double timeBlock = std::chrono::duration<double>(end - start).count();
std::cout << "Parallel Block (" << blockSize << "x" << blockSize << "): "
<< timeBlock << " s | "
<< (compareMatrices(C_serial, C_block) ? "Match" : "Mismatch") << "\n";
if (N < 5)
printMatrix(C_block, "C_block");
return 0;
}

View File

@ -142,16 +142,22 @@ int main()
fabs(mouse.y - screenPos.y) < 40)
{
c.FlipForward(); //<-----Animation Start
//Neu Counter
counter++;
if (state == GameState::Idle) //Neu (Ü4)
if (state == GameState::Idle) //neu Ü4
{
state = GameState::OneFlipped;
else
counter++;
}
else if (state == GameState::OneFlipped && first && &c != first)
{
state = GameState::LockInput;
counter++;
}
break; // 🔒 nur EIN Würfel pro Klick
}
}
}
}

View File

@ -1,8 +0,0 @@
cmake_minimum_required(VERSION 3.20)
project(prog3b_652)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_executable(prog3b main.cpp)

View File

View File

View File

@ -1,122 +0,0 @@
#include <iostream>
#include <fstream>
#include <vector>
#include <thread>
#include <chrono>
#include <cstdlib>
// =====================
// Datei einlesen
// =====================
void readFile(const std::string& filename, std::vector<int>& data)
{
std::ifstream file(filename);
int value;
while (file >> value)
data.push_back(value);
}
// =====================
// Serielle Auswertung
// =====================
int countSerial(const std::vector<int>& messungen)
{
if (messungen.size() < 2)
return 0;
int increases = 0;
for (size_t i = 1; i < messungen.size(); ++i)
if (messungen[i] > messungen[i - 1])
++increases;
return increases;
}
// =====================
// Parallele Auswertung
// =====================
int countParallel(const std::vector<int>& messungen, int numThreads)
{
if (messungen.size() < 2)
return 0;
int totalComparisons = messungen.size() - 1;
if (numThreads > totalComparisons)
numThreads = totalComparisons;
std::vector<int> results(numThreads, 0);
std::vector<std::thread> threads;
int base = totalComparisons / numThreads;
int remainder = totalComparisons % numThreads;
int idx = 1;
for (int t = 0; t < numThreads; ++t)
{
int startIdx = idx;
int count = base + (t < remainder ? 1 : 0);
int endIdx = idx + count - 1;
idx = endIdx + 1;
threads.emplace_back([&, t, startIdx, endIdx]()
{
int localCount = 0;
for (int i = startIdx; i <= endIdx; ++i)
if (messungen[i] > messungen[i - 1])
++localCount;
results[t] = localCount;
});
}
for (auto& th : threads)
th.join();
int total = 0;
for (int r : results)
total += r;
return total;
}
// =====================
// main
// =====================
int main()
{
std::vector<int> messungen;
// ===== Variante A: Datei =====
readFile("measurements.txt", messungen);
// ===== Variante B: künstliche Daten (statt Datei) =====
/*
int value = 0;
for (size_t i = 0; i < 100000000; ++i)
messungen.push_back(value += (rand() % 3 - 1));
*/
// ===== Seriell =====
auto start = std::chrono::steady_clock::now();
int serialResult = countSerial(messungen);
auto end = std::chrono::steady_clock::now();
std::chrono::duration<double> serialTime = end - start;
std::cout << "Seriell: " << serialResult
<< " | Took: " << serialTime.count() << " s\n";
// ===== Parallel =====
int numThreads = std::thread::hardware_concurrency();
if (numThreads == 0) numThreads = 4;
start = std::chrono::steady_clock::now();
int parallelResult = countParallel(messungen, numThreads);
end = std::chrono::steady_clock::now();
std::chrono::duration<double> parallelTime = end - start;
std::cout << "Parallel: " << parallelResult
<< " | Took: " << parallelTime.count() << " s\n";
return 0;
}

File diff suppressed because it is too large Load Diff