3808 |
04 Jul 19 |
peter |
// $Id$ |
3808 |
04 Jul 19 |
peter |
2 |
|
3808 |
04 Jul 19 |
peter |
3 |
/* |
3808 |
04 Jul 19 |
peter |
Copyright (C) 2019 Peter Johansson |
3808 |
04 Jul 19 |
peter |
5 |
|
3808 |
04 Jul 19 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
3808 |
04 Jul 19 |
peter |
7 |
|
3808 |
04 Jul 19 |
peter |
The yat library is free software; you can redistribute it and/or |
3808 |
04 Jul 19 |
peter |
modify it under the terms of the GNU General Public License as |
3808 |
04 Jul 19 |
peter |
published by the Free Software Foundation; either version 3 of the |
3808 |
04 Jul 19 |
peter |
License, or (at your option) any later version. |
3808 |
04 Jul 19 |
peter |
12 |
|
3808 |
04 Jul 19 |
peter |
The yat library is distributed in the hope that it will be useful, |
3808 |
04 Jul 19 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
3808 |
04 Jul 19 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3808 |
04 Jul 19 |
peter |
General Public License for more details. |
3808 |
04 Jul 19 |
peter |
17 |
|
3808 |
04 Jul 19 |
peter |
You should have received a copy of the GNU General Public License |
3808 |
04 Jul 19 |
peter |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
3808 |
04 Jul 19 |
peter |
20 |
*/ |
3808 |
04 Jul 19 |
peter |
21 |
|
3808 |
04 Jul 19 |
peter |
22 |
#include <config.h> |
3808 |
04 Jul 19 |
peter |
23 |
|
3808 |
04 Jul 19 |
peter |
24 |
#include "Suite.h" |
3808 |
04 Jul 19 |
peter |
25 |
|
3808 |
04 Jul 19 |
peter |
26 |
#include "yat/utility/Scheduler.h" |
3808 |
04 Jul 19 |
peter |
27 |
#include "yat/utility/Matrix.h" |
3808 |
04 Jul 19 |
peter |
28 |
|
3808 |
04 Jul 19 |
peter |
29 |
#include <boost/make_shared.hpp> |
3808 |
04 Jul 19 |
peter |
30 |
#include <boost/shared_ptr.hpp> |
3808 |
04 Jul 19 |
peter |
31 |
|
3808 |
04 Jul 19 |
peter |
32 |
#include <cstdlib> |
3808 |
04 Jul 19 |
peter |
33 |
#include <exception> |
3808 |
04 Jul 19 |
peter |
34 |
#include <iostream> |
3808 |
04 Jul 19 |
peter |
35 |
#include <set> |
3808 |
04 Jul 19 |
peter |
36 |
#include <unistd.h> |
3808 |
04 Jul 19 |
peter |
37 |
|
3808 |
04 Jul 19 |
peter |
38 |
using namespace theplu::yat; |
3808 |
04 Jul 19 |
peter |
39 |
|
3808 |
04 Jul 19 |
peter |
40 |
using utility::Matrix; |
3808 |
04 Jul 19 |
peter |
41 |
|
3808 |
04 Jul 19 |
peter |
42 |
class MyJob : public utility::Scheduler::Job |
3808 |
04 Jul 19 |
peter |
43 |
{ |
3808 |
04 Jul 19 |
peter |
44 |
public: |
3808 |
04 Jul 19 |
peter |
45 |
MyJob(const Matrix& x, const Matrix& y, Matrix& z, size_t col) |
3808 |
04 Jul 19 |
peter |
46 |
: x_(&x), y_(&y), z_(&z), col_(col) |
3808 |
04 Jul 19 |
peter |
47 |
{} |
3808 |
04 Jul 19 |
peter |
48 |
|
3808 |
04 Jul 19 |
peter |
49 |
void operator()(void) |
3808 |
04 Jul 19 |
peter |
50 |
{ |
3808 |
04 Jul 19 |
peter |
51 |
std::cerr << '.'; |
3808 |
04 Jul 19 |
peter |
52 |
z_->column_view(col_) = |
3808 |
04 Jul 19 |
peter |
53 |
x_->column_const_view(col_) + y_->column_const_view(col_); |
3808 |
04 Jul 19 |
peter |
54 |
} |
3808 |
04 Jul 19 |
peter |
55 |
|
3808 |
04 Jul 19 |
peter |
56 |
private: |
3808 |
04 Jul 19 |
peter |
57 |
Matrix const * x_; |
3808 |
04 Jul 19 |
peter |
58 |
Matrix const * y_; |
3808 |
04 Jul 19 |
peter |
59 |
Matrix* z_; |
3808 |
04 Jul 19 |
peter |
60 |
size_t col_; |
3808 |
04 Jul 19 |
peter |
61 |
}; |
3808 |
04 Jul 19 |
peter |
62 |
|
3808 |
04 Jul 19 |
peter |
63 |
|
3808 |
04 Jul 19 |
peter |
64 |
int main(int argc, char* argv[]) |
3808 |
04 Jul 19 |
peter |
65 |
{ |
3808 |
04 Jul 19 |
peter |
66 |
test::Suite suite(argc, argv); |
3808 |
04 Jul 19 |
peter |
67 |
|
3808 |
04 Jul 19 |
peter |
68 |
try { |
3808 |
04 Jul 19 |
peter |
69 |
utility::Scheduler scheduler(2); |
3808 |
04 Jul 19 |
peter |
70 |
size_t m = 10; |
3808 |
04 Jul 19 |
peter |
71 |
size_t n = 1000; |
3808 |
04 Jul 19 |
peter |
72 |
utility::Matrix x(m, n, 1); |
3808 |
04 Jul 19 |
peter |
73 |
utility::Matrix y(m, n, 2); |
3808 |
04 Jul 19 |
peter |
74 |
utility::Matrix z(m, n); |
3808 |
04 Jul 19 |
peter |
75 |
for (size_t i=0; i<n; ++i) { |
3808 |
04 Jul 19 |
peter |
76 |
std::cerr << ';'; |
3808 |
04 Jul 19 |
peter |
77 |
boost::shared_ptr<MyJob> job(new MyJob(x, y, z, i)); |
3808 |
04 Jul 19 |
peter |
78 |
scheduler.submit(job); |
3808 |
04 Jul 19 |
peter |
79 |
} |
3808 |
04 Jul 19 |
peter |
80 |
scheduler.wait(); |
3808 |
04 Jul 19 |
peter |
81 |
} |
3808 |
04 Jul 19 |
peter |
82 |
catch (std::exception& e) { |
3808 |
04 Jul 19 |
peter |
83 |
suite.err() << "error: " << e.what() << "\n"; |
3808 |
04 Jul 19 |
peter |
84 |
suite.add(false); |
3808 |
04 Jul 19 |
peter |
85 |
} |
3808 |
04 Jul 19 |
peter |
86 |
|
3808 |
04 Jul 19 |
peter |
87 |
return suite.return_value(); |
3808 |
04 Jul 19 |
peter |
88 |
} |