Commit b7c5674c authored by Mario Bajer's avatar Mario Bajer
Browse files

fixed broken dimensions

fixed multiplication error for dim > and < MAX_THREAD
parent 8dd40bd0
......@@ -8,9 +8,9 @@
std::mutex m;
void Matrix::print(std::ostream& a_r0s){
for(int i = 0; i < this->dimy; i++){
for(int i = 0; i < this->dimx; i++){
a_r0s << "<p>";
for(int j = 0; j < this->dimx; j++){
for(int j = 0; j < this->dimy; j++){
a_r0s << (*this)(i,j) << " ";
}
a_r0s << "</p>";
......@@ -155,14 +155,21 @@ Matrix Matrix::operator*(const Matrix& b) {
}
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++) {
bool helper;
(*this).set(i,j);
for (int k = 0; k < this->dimy; k++) {
helper = (*this)(i, j) != (a(i, k) & b(k, j));
for (int k = 0; k < a.dimy; k++) {
if (k > 0){
helper3 = a(i, k) & b(k, j);
helper4 = helper2;
helper2 = helper4 ^ helper3;
}
if (helper) {
helper1 = a(i, k) & b(k, j);
if (k == 0){
helper2 = helper1;
}
}
if (helper2) {
(*this).set(i,j);
}else{
(*this).reset(i,j);
......@@ -171,16 +178,16 @@ void Matrix::threadedmult(Matrix a, Matrix b, std::size_t from, std::size_t to){
}
}
void Matrix::set(std::size_t y, std::size_t x){
std::size_t matrixPos = dimx*y + x;
void Matrix::set(std::size_t x, std::size_t y){
std::size_t matrixPos = dimx*x + y;
const std::size_t arrayPos = matrixPos / (sizeof(uint64_t)*8);
const std::size_t bitPos = matrixPos % (sizeof(uint64_t)*8);
const uint64_t pos = 1;
data[arrayPos] |= (pos << bitPos);
}
void Matrix::reset(std::size_t y, std::size_t x){
std::size_t matrixPos = dimx*y + x;
void Matrix::reset(std::size_t x, std::size_t y){
std::size_t matrixPos = dimx*x + y;
const std::size_t arrayPos = matrixPos / (sizeof(uint64_t)*8);
const std::size_t bitPos = matrixPos % (sizeof(uint64_t)*8);
const uint64_t pos = 1;
......
......@@ -55,11 +55,11 @@ public:
/** @brief Setzt ein Bit an stelle (y,x) auf 1
* */
void set(std::size_t y, std::size_t x);
void set(std::size_t x, std::size_t y);
/** @brief Setzt ein Bit an stelle (y,x) auf 0
* */
void reset(std::size_t y, std::size_t x);
void reset(std::size_t x, std::size_t y);
/** @brief Prüft ob eine Addition möglich ist. (Dimensionen exakt gleich)
*
......@@ -78,8 +78,8 @@ public:
* @param unsigned x - Spalte der Matrix
* @return gibt den Wert der Matrix an der Stelle zurück
* */
inline bool operator()(unsigned y, unsigned x) const {
std::size_t matrixPos = dimx*y + x;
inline bool operator()(unsigned x, unsigned y) const {
std::size_t matrixPos = dimx*x + y;
const std::size_t arrayPos = matrixPos / (sizeof(uint64_t)*8);
const std::size_t bitPos = matrixPos % (sizeof(uint64_t)*8);
const uint64_t pos = 1;
......
......@@ -28,7 +28,7 @@ int main(){
cout << "<p>File " << folderpath << " wurde gelöscht!</p>" << endl;
}
cout << "<a href=\"http://localhost:80/index.html\">Back to Index</a>";
cout << "<a href=\"http://localhost:80/cgi-bin/list.cgi\">Back</a>";
cout << "</div>" << endl;
cout << "</body>\n";
cout << "</html>\n";
......
......@@ -17,7 +17,6 @@ int main(){
auto fi1 = formData.getElement("dimensionx");
if( !fi1->isEmpty() && fi1 != (*formData).end()) {
dimx = stoi(**fi1);
cout << "<p>" << dimx << "</p>" << endl;
}
else
{
......@@ -26,14 +25,13 @@ int main(){
auto fi2 = formData.getElement("dimensiony");
if( !fi2->isEmpty() && fi2 != (*formData).end()) {
dimy = stoi(**fi2);
cout << "<p>" << dimy << "</p>" << endl;
}
else
{
cout << "No valid dimension for X entered!" << endl;
cout << "No valid dimension for Y entered!" << endl;
}
if((dimx != 0) && (dimy != 0)){
Matrix matrix(dimx, dimy);
Matrix matrix(dimy, dimx);
matrix.fillRND();
matrix.saveMatrix();
}
......
......@@ -55,8 +55,8 @@ int main(){
vector<string> rs = parseHeader(entry.path());
cout << "<tr>" << endl;
cout << "<td>" << rs[0] << "</td>" << endl;
cout << "<td>" << rs[1] << "</td>" << endl;
cout << "<td>" << rs[2] << "</td>" << endl;
cout << "<td>" << rs[1] << "</td>" << endl;
cout << "<td>" << entry.path() << "</td>" << endl;
cout << R"(<form action="/cgi-bin/show.cgi" method="GET">)" << endl;
cout << "<td>" << endl;
......
......@@ -23,19 +23,21 @@ int main(){
string idB = parseCgiElement(formData, "matrixB");
string operation = parseCgiElement(formData, "rechenop");
Matrix a(1, 1);
vector<string> matrixA = parseHeader("Json/" + idA);
vector<string> matrixB = parseHeader("Json/" + idB);
Matrix a(stoi(matrixA[2]), stoi(matrixA[1]));
a.getmatrixfromfile("Json/" + idA);
Matrix b(1, 1);
Matrix b(stoi(matrixB[2]), stoi(matrixB[1]));
b.getmatrixfromfile("Json/" + idB);
// cout << "<p>Matrix A:</p>" << endl;
// a.print(cout);
// cout << "<p>Matrix B:</p>" << endl;
// b.print(cout);
vector<string> matrixA = parseHeader("Json/" + idA);
vector<string> matrixB = parseHeader("Json/" + idB);
int tsize = stoi(matrixA[1]) / MAX_THREADS;
// cout << stoi(matrixA[1]) << " und " << stoi(matrixB[2]) << " tsize is " << tsize << endl;
int dimyA = stoi(matrixA[2]);
int tsize = dimyA / MAX_THREADS;
thread matrixthread[MAX_THREADS];
if((operation.at(0) == '+') && a.checkAddSub(b)) {
......@@ -51,19 +53,18 @@ int main(){
}else if((operation.at(0) == '*') && a.checkMult(b)) {
Matrix c(stoi(matrixA[1]),stoi(matrixB[2]));
auto start = std::chrono::high_resolution_clock::now();
if(stoi(matrixA[1]) >= MAX_THREADS) {
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);
}
for (auto &i : matrixthread) {
i.join();
for (size_t i = 0; i < MAX_THREADS; i++) {
matrixthread[i].join();
}
if (((stoi(matrixA[1]) / MAX_THREADS) % MAX_THREADS) != 0) {
callMult(a, b, c, stoi(matrixA[1]) - ((stoi(matrixA[1]) / MAX_THREADS) % MAX_THREADS),
stoi(matrixA[1]));
if ((tsize % MAX_THREADS) != 0) {
callMult(a, b, c, dimyA - (tsize % MAX_THREADS), dimyA);
}
}else{
callMult(a, b, c, 0, stoi(matrixA[1]));
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