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
7feec40d
Commit
7feec40d
authored
Jun 09, 2020
by
Mario Bajer
Browse files
callMult & threadedmult changed to pass amtrices by ref
parent
b7c5674c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Matrix.cpp
View file @
7feec40d
...
...
@@ -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
;
}
...
...
Matrix.hpp
View file @
7feec40d
...
...
@@ -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
;
...
...
multi.cpp
View file @
7feec40d
...
...
@@ -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
;
...
...
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