ASL  0.1.7
Advanced Simulation Library
testMatrixOfElements.cc
Go to the documentation of this file.
1 /*
2  * Advanced Simulation Library <http://asl.org.il>
3  *
4  * Copyright 2015 Avtech Scientific <http://avtechscientific.com>
5  *
6  *
7  * This file is part of Advanced Simulation Library (ASL).
8  *
9  * ASL is free software: you can redistribute it and/or modify it
10  * under the terms of the GNU Affero General Public License as
11  * published by the Free Software Foundation, version 3 of the License.
12  *
13  * ASL is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Affero General Public License for more details.
17  *
18  * You should have received a copy of the GNU Affero General Public License
19  * along with ASL. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 
28 #include "acl/acl.h"
29 #include "acl/aclGenerators.h"
33 #include "math/aslMatrices.h"
34 #include "acl/Kernels/aclKernel.h"
35 #include "acl/DataTypes/aclArray.h"
36 
37 using namespace asl;
38 using namespace acl;
39 using namespace std;
40 
42 {
43  cout << "Test of \"Matrix Operations\" function..." << flush;
44 
45  VectorOfElements vec0(3);
46  VectorOfElements vec1(1);
47  copy(generateVEData<cl_float>(10u,3u),vec0);
48  copy(generateVEData<cl_float>(10u,1u),vec1);
49 
50  Kernel k;
51  {
52  using namespace elementOperators;
53  k << (vec0=generateVEConstant(0.1f,1.f,2.f));
54  k << (vec1=(elementProduct(generateVEConstant(0.f,1.f,2.f),vec0)*generateVEConstant(1.f,0.f,2.f))*vec0);
55  }
56  k.setup();
57  k.compute();
58 
59  vector<cl_float> output(10);
60  copy(vec1[0], output);
61 
62  bool status(output[1] == 20.5);
63  errorMessage(status);
64 
65  return status;
66 }
67 
68 
70 {
71  cout << "Test of \"System Solve Cramer's rule\" function..." << flush;
72 
73  VectorOfElements vecB(2);
74  VectorOfElements vecX(2);
75  copy(generateVEData<cl_float>(10u,2u),vecB);
76  copy(generateVEData<cl_float>(10u,2u),vecX);
77 
78  auto matA(generateMEConstant(makeAMatr(makeAVec(4.,1.),makeAVec(1.,3.))));
79 
80  Kernel k;
81  {
82  using namespace elementOperators;
83  k << (vecB=generateVEConstant(1.f,2.f));
84  k << gcSolveSystem(matA,vecB,vecX);
85  }
86  k.setup();
87  k.compute();
88 
89  vector<cl_float> output(10);
90  copy(vecX[0], output);
91 
92  bool status(output[1] > 0.09 && output[1] < .1);
93  errorMessage(status);
94 
95  return status;
96 }
97 
99 {
100  cout << "Test of \"System Solve congugate gradient method\" function..." << flush;
101 
102  VectorOfElements vecB(2);
103  VectorOfElements vecX(2);
104  copy(generateVEData<cl_float>(10u,2u),vecB);
105  copy(generateVEData<cl_float>(10u,2u),vecX);
106 
107  auto matA(generateMEConstant(makeAMatr(makeAVec(4.,1.),makeAVec(1.,3.))));
108 
109  Kernel k;
110  {
111  using namespace elementOperators;
112  k << (vecB=generateVEConstant(1.f,2.f));
113  k << gcSolveSystemCG(matA,vecB,vecX);
114  }
115  k.setup();
116  k.compute();
117 
118  vector<cl_float> output(10);
119  copy(vecX[0], output);
120 
121  bool status(output[1] > 0.09 && output[1] < .1);
122  errorMessage(status);
123 
124  return status;
125 }
126 
127 
128 int main()
129 {
130  bool allTestsPassed(true);
131 
132  allTestsPassed &= testMatrixOperations();
133  allTestsPassed &= testSystemSolve();
134  allTestsPassed &= testSystemSolveCG();
135 
136  return allTestsPassed ? EXIT_SUCCESS : EXIT_FAILURE;
137 }
Advanced Simulation Library.
Definition: aslDataInc.h:30
Advanced Computational Language.
Definition: acl.h:40
AVec< T > makeAVec(T a1)
vector< Element > gcSolveSystem(const MatrixOfElements &a, const VectorOfElements &b, const VectorOfElements &x)
generates code for solving the solution of a system of linear equations
void errorMessage(cl_int status, const char *errorMessage)
Prints errorMessage and exits depending on the status.
Matrices.
bool testSystemSolve()
OpenCl Kernel generator.
Definition: aclKernel.h:48
vector< Element > gcSolveSystemCG(const MatrixOfElements &a, const VectorOfElements &b, const VectorOfElements &x)
generates code for solving the solution of a system of linear equations
cl_int flush(void)
Definition: cl.hpp:7042
The class represents several Element.
bool testSystemSolveCG()
int main()
VectorOfElements generateVEConstant(T a)
Generates VectorOfElements with 1 Element acl::Constant with value a.
void copy(MemBlock &source, T *destination)
void compute()
MatrixOfElements generateMEConstant(const asl::AMatr< T > &a)
Generates VectorOfElements correspondinng to a.
bool testMatrixOperations()
void setup()