Commit 29deb329 authored by Mario Bajer's avatar Mario Bajer
Browse files

threaded mult mit c by ref

parent 9f002cd5
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
#include <thread> #include <thread>
#define MAX_THREADS 4 #define MAX_THREADS 4
void callMult(Matrix* a, Matrix* b, Matrix c, size_t from, size_t to){ // c auch als ref! void callMult(Matrix* a, Matrix* b, Matrix *c, size_t from, size_t to){ // c auch als ref!
c.threadedmult(a,b,from,to); c->threadedmult(a,b,from,to);
} }
int main(){ int main(){
...@@ -55,16 +55,16 @@ int main(){ ...@@ -55,16 +55,16 @@ int main(){
auto start = std::chrono::high_resolution_clock::now(); auto start = std::chrono::high_resolution_clock::now();
if(stoi(matrixA[2]) >= (2 * MAX_THREADS)) { if(stoi(matrixA[2]) >= (2 * MAX_THREADS)) {
for (size_t i = 0; i < MAX_THREADS; i++) { for (size_t i = 0; i < MAX_THREADS; i++) {
matrixthread[i] = thread(callMult, &a, &b, c, (i * tsize), (i * tsize) + tsize - 1); // c als ref matrixthread[i] = thread(callMult, &a, &b, &c, (i * tsize), (i * tsize) + tsize - 1); // c als ref
} }
for (size_t i = 0; i < MAX_THREADS; i++) { for (size_t i = 0; i < MAX_THREADS; i++) {
matrixthread[i].join(); matrixthread[i].join();
} }
if ((tsize % MAX_THREADS) != 0) { if ((tsize % MAX_THREADS) != 0) {
callMult(&a, &b, c, dimyA - (tsize % MAX_THREADS), dimyA); callMult(&a, &b, &c, dimyA - (tsize % MAX_THREADS), dimyA);
} }
}else{ }else{
callMult(&a, &b, c, 0, stoi(matrixA[2])); callMult(&a, &b, &c, 0, stoi(matrixA[2]));
} }
auto end = std::chrono::high_resolution_clock::now(); auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> elapsed = end - start; std::chrono::duration<double> elapsed = end - start;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment