-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathValidation.cpp
executable file
·145 lines (108 loc) · 2.53 KB
/
Validation.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <cmath>
#include <stdlib.h>
#define epsilon 1.e-8
using namespace std;
int main(int argc, char* argv[]){
double **A, **Ucpu, **Vcpu, **Scpu, **Uomp, **Vomp, **Somp;
double rUcpu, rVcpu, rScpu, rUomp, rVomp, rSomp, resU,resV,resS;
int N,M;
string P;
if(argc>1){
P = argv[1];
}
ifstream matrixUcpu("matrixUcpu");
if(!(matrixUcpu.is_open())){
cout<<"Error: file not found"<<endl;
return 0;
}
ifstream matrixVcpu("matrixVcpu");
if(!(matrixVcpu.is_open())){
cout<<"Error: file not found"<<endl;
return 0;
}
ifstream matrixScpu("matrixScpu");
if(!(matrixScpu.is_open())){
cout<<"Error: file not found"<<endl;
return 0;
}
ifstream matrixUomp("matrixUomp");
if(!(matrixUomp.is_open())){
cout<<"Error: file not found"<<endl;
return 0;
}
ifstream matrixVomp("matrixVomp");
if(!(matrixVomp.is_open())){
cout<<"Error: file not found"<<endl;
return 0;
}
ifstream matrixSomp("matrixSomp");
if(!(matrixSomp.is_open())){
cout<<"Error: file not found"<<endl;
return 0;
}
matrixUcpu>>M;
matrixUcpu>>N;
//cout<<M<<' '<<N<<endl;
Ucpu = new double *[N];
Vcpu = new double *[N];
Scpu = new double *[N];
Uomp = new double *[N];
Vomp = new double *[N];
Somp = new double *[N];
for(int i =0;i<N;i++){
Ucpu[i] = new double[N];
Vcpu[i] = new double[N];
Scpu[i] = new double[N];
Uomp[i] = new double[N];
Vomp[i] = new double[N];
Somp[i] = new double[N];
}
for(int i =0; i<M;i++){
for(int j =0; j<N;j++){
matrixUcpu>>Ucpu[i][j];
matrixVcpu>>Vcpu[i][j];
matrixScpu>>Scpu[i][j];
matrixUomp>>Uomp[i][j];
matrixVomp>>Vomp[i][j];
matrixSomp>>Somp[i][j];
}
}
matrixUcpu.close();
matrixVcpu.close();
matrixScpu.close();
matrixUomp.close();
matrixVomp.close();
matrixSomp.close();
rUcpu = 0.0;
rVcpu = 0.0;
rScpu =0.0;
rUomp = 0.0;
rVomp = 0.0;
rSomp = 0.0;
for(int i = 0; i<N; i++){
for(int j =0; j<N;j++){
rUcpu += (abs(Ucpu[i][j]));
rVcpu += (abs(Vcpu[i][j]));
rScpu += (abs(Scpu[i][j]));
rUomp += (abs(Uomp[i][j]));
rVomp += (abs(Vomp[i][j]));
rSomp += (abs(Somp[i][j]));
}
}
resU = abs(rUcpu - rUomp);
resV = abs(rVcpu - rVomp);
resS = abs(rScpu - rSomp);
if((resU >= 0.0 && resU<=epsilon) && (resV >= 0.0 && resV <= epsilon) && (resS >= 0.0 && resS <= epsilon)){
cout<<"VALID!"<<endl<<endl;
}
else{
cout<<"NOT VALID!"<<endl<<endl;
}
if(P == "-p"){
cout<<"difference in U: "<<resU<<endl<<"difference in V: "<<resV<<endl<<"difference in S: "<<resS<<endl;
}
return 0;
}