Commit 7feec40d authored by Mario Bajer's avatar Mario Bajer
Browse files

callMult & threadedmult changed to pass amtrices by ref

parent b7c5674c
......@@ -154,17 +154,17 @@ Matrix Matrix::operator*(const Matrix& b) {
return c;
}
void Matrix::threadedmult(Matrix a, Matrix b, std::size_t from, std::size_t to){
void Matrix::threadedmult(Matrix* a, Matrix* b, std::size_t from, std::size_t to){
bool helper1, helper2, helper3, helper4;
for (size_t i = from; i < to; i++) {
for (int j = 0; j < b.dimx; j++) {
for (int k = 0; k < a.dimy; k++) {
for (int j = 0; j < (*b).dimx; j++) {
for (int k = 0; k < (*a).dimy; k++) {
if (k > 0){
helper3 = a(i, k) & b(k, j);
helper3 = (*a)(i, k) & (*b)(k, j);
helper4 = helper2;
helper2 = helper4 ^ helper3;
}
helper1 = a(i, k) & b(k, j);
helper1 = (*a)(i, k) & (*b)(k, j);
if (k == 0){
helper2 = helper1;
}
......
......@@ -112,7 +112,7 @@ public:
* @param Matrix a, Matrix b, std::size_t from, std::size_t to
* @return void
* */
void threadedmult(Matrix a, Matrix b, std::size_t from, std::size_t to);
void threadedmult(Matrix* a, Matrix* b, std::size_t from, std::size_t to);
private:
int ID;
......
......@@ -8,7 +8,7 @@
#include <thread>
#define MAX_THREADS 4
void callMult(Matrix a, Matrix b, Matrix c, size_t from, size_t to){
void callMult(Matrix* a, Matrix* b, Matrix c, size_t from, size_t to){
c.threadedmult(a,b,from,to);
}
......@@ -55,16 +55,16 @@ int main(){
auto start = std::chrono::high_resolution_clock::now();
if(stoi(matrixA[2]) >= (2 * MAX_THREADS)) {
for (size_t i = 0; i < MAX_THREADS; i++) {
matrixthread[i] = thread(callMult, a, b, c, (i * tsize), (i * tsize) + tsize - 1);
matrixthread[i] = thread(callMult, &a, &b, c, (i * tsize), (i * tsize) + tsize - 1);
}
for (size_t i = 0; i < MAX_THREADS; i++) {
matrixthread[i].join();
}
if ((tsize % MAX_THREADS) != 0) {
callMult(a, b, c, dimyA - (tsize % MAX_THREADS), dimyA);
callMult(&a, &b, c, dimyA - (tsize % MAX_THREADS), dimyA);
}
}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();
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