1 /*
2     Copyright (c) 2005-2021 Intel Corporation
3 
4     Licensed under the Apache License, Version 2.0 (the "License");
5     you may not use this file except in compliance with the License.
6     You may obtain a copy of the License at
7 
8         http://www.apache.org/licenses/LICENSE-2.0
9 
10     Unless required by applicable law or agreed to in writing, software
11     distributed under the License is distributed on an "AS IS" BASIS,
12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13     See the License for the specific language governing permissions and
14     limitations under the License.
15 */
16 
17 #ifndef TBB_examples_parallel_preorder_matrix_H
18 #define TBB_examples_parallel_preorder_matrix_H
19 
20 class Matrix {
21     static const int n = 20;
22     float array[n][n];
23 
24 public:
Matrix()25     Matrix() {}
Matrix(float z)26     Matrix(float z) {
27         for (int i = 0; i < n; ++i)
28             for (int j = 0; j < n; ++j)
29                 array[i][j] = i == j ? z : 0;
30     }
operator -(const Matrix & x)31     friend Matrix operator-(const Matrix& x) {
32         Matrix result;
33         for (int i = 0; i < n; ++i)
34             for (int j = 0; j < n; ++j)
35                 result.array[i][j] = -x.array[i][j];
36         return result;
37     }
operator +(const Matrix & x,const Matrix & y)38     friend Matrix operator+(const Matrix& x, const Matrix& y) {
39         Matrix result;
40         for (int i = 0; i < n; ++i)
41             for (int j = 0; j < n; ++j)
42                 result.array[i][j] = x.array[i][j] + y.array[i][j];
43         return result;
44     }
operator -(const Matrix & x,const Matrix & y)45     friend Matrix operator-(const Matrix& x, const Matrix& y) {
46         Matrix result;
47         for (int i = 0; i < n; ++i)
48             for (int j = 0; j < n; ++j)
49                 result.array[i][j] = x.array[i][j] - y.array[i][j];
50         return result;
51     }
operator *(const Matrix & x,const Matrix & y)52     friend Matrix operator*(const Matrix& x, const Matrix& y) {
53         Matrix result(0);
54         for (int i = 0; i < n; ++i)
55             for (int k = 0; k < n; ++k)
56                 for (int j = 0; j < n; ++j)
57                     result.array[i][j] += x.array[i][k] * y.array[k][j];
58         return result;
59     }
60 };
61 
62 #endif /* TBB_examples_parallel_preorder_matrix_H */
63