Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Thomas Zeitlhofer
ESE_Zeitlhofer_Bajer
Commits
b7c5674c
Commit
b7c5674c
authored
Jun 06, 2020
by
Mario Bajer
Browse files
fixed broken dimensions
fixed multiplication error for dim > and < MAX_THREAD
parent
8dd40bd0
Changes
6
Hide whitespace changes
Inline
Side-by-side
Matrix.cpp
View file @
b7c5674c
...
...
@@ -8,9 +8,9 @@
std
::
mutex
m
;
void
Matrix
::
print
(
std
::
ostream
&
a_r0s
){
for
(
int
i
=
0
;
i
<
this
->
dim
y
;
i
++
){
for
(
int
i
=
0
;
i
<
this
->
dim
x
;
i
++
){
a_r0s
<<
"<p>"
;
for
(
int
j
=
0
;
j
<
this
->
dim
x
;
j
++
){
for
(
int
j
=
0
;
j
<
this
->
dim
y
;
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
;
}
helper1
=
a
(
i
,
k
)
&
b
(
k
,
j
);
if
(
k
==
0
){
helper2
=
helper1
;
}
}
if
(
helper
)
{
if
(
helper
2
)
{
(
*
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
;
...
...
Matrix.hpp
View file @
b7c5674c
...
...
@@ -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
;
...
...
delete.cpp
View file @
b7c5674c
...
...
@@ -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
"
;
...
...
generate.cpp
View file @
b7c5674c
...
...
@@ -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
(
dim
x
,
dim
y
);
Matrix
matrix
(
dim
y
,
dim
x
);
matrix
.
fillRND
();
matrix
.
saveMatrix
();
}
...
...
list.cpp
View file @
b7c5674c
...
...
@@ -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
;
...
...
multi.cpp
View file @
b7c5674c
...
...
@@ -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
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment