ALL
0.9.4
A Loadbalacing Library
Toggle main menu visibility
Loading...
Searching...
No Matches
TestCompare.cpp
Go to the documentation of this file.
1
/*
2
Copyright 2020-2020 Stephan Schulz, Forschungszentrum Juelich GmbH, Germany
3
Copyright 2026-2026 Jonas Kroschewski, Forschungszentrum Juelich GmbH, Germany
4
5
Redistribution and use in source and binary forms, with or without
6
modification, are permitted provided that the following conditions are met:
7
8
1. Redistributions of source code must retain the above copyright notice,
9
this list of conditions and the following disclaimer.
10
11
2. Redistributions in binary form must reproduce the above copyright notice,
12
this list of conditions and the following disclaimer in the documentation
13
and/or other materials provided with the distribution.
14
15
3. Neither the name of the copyright holder nor the names of its contributors
16
may be used to endorse or promote products derived from this software without
17
specific prior written permission.
18
19
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
POSSIBILITY OF SUCH DAMAGE.
30
*/
31
32
#include <stdlib.h>
33
#include <stdio.h>
34
#include <string.h>
35
#include <math.h>
36
#include <vector>
37
38
// Returns 0 on Match and 2 on Bad Match.
39
// Other errors return different codes.
40
41
#define EXIT_NOMATCH 2
42
43
typedef
std::vector<std::vector<std::vector<std::vector<double>>>>
vector4d
;
44
45
// This assumes the following format:
46
// First two lines .must. be:
47
// Ranks: %d
48
// Number of Steps: %d
49
// Then lines are ignored except
50
// [%d,%d,%d] Result Vertex: %f %f %f
51
// With: [Step, Rank, Vertex]
52
// The lines need not be ordered, but must all be placed after Number
53
// of Steps
54
// Output: Data[Step][Rank][Vertex][Dimension]
55
vector4d
*
LoadTest
(
char
*FileName)
56
{
57
FILE* File = fopen(FileName,
"r"
);
58
if
(!File)
59
{
60
fprintf(stderr,
"Could not open file '%s'\n"
, FileName);
61
exit(EXIT_FAILURE);
62
}
63
const
int
LineLength = 8192;
64
char
Line[LineLength];
65
int
Dimension = 3;
66
if
(fgets(Line, LineLength, File) == NULL)
67
{
68
fprintf(stderr,
"Could not read file '%s'\n"
, FileName);
69
exit(EXIT_FAILURE);
70
}
71
int
Ranks;
72
int
ReadCount = sscanf(Line,
"Ranks: %d"
, &Ranks);
73
if
(ReadCount<1)
74
{
75
fprintf(stderr,
"Could not parse ranks in '%s'\n"
, FileName);
76
exit(EXIT_FAILURE);
77
}
78
if
(fgets(Line, LineLength, File) == NULL)
79
{
80
fprintf(stderr,
"Could not read file '%s'\n"
, FileName);
81
exit(EXIT_FAILURE);
82
}
83
int
Steps;
84
ReadCount = sscanf(Line,
"Number of Steps: %d"
, &Steps);
85
if
(ReadCount<1)
86
{
87
fprintf(stderr,
"Could not parse number of steps in '%s'\n"
, FileName);
88
exit(EXIT_FAILURE);
89
}
90
91
vector4d
* Data =
new
vector4d
;
//Data[Step][Rank][Vertex][Dimension]
92
(*Data).resize(Steps);
93
(*Data)[0].resize(1);
94
(*Data)[0][0].resize(1);
95
(*Data)[0][0][0].resize(1);
96
97
size_t
CurrentStep = 0;
98
while
(fgets(Line, LineLength, File) != NULL)
99
{
100
double
InRankData[3];
101
size_t
CurrentRank;
102
size_t
CurrentVertex;
103
ReadCount = sscanf(Line,
"[%lu,%lu,%lu] Result Vertex: %lf %lf %lf"
,
104
&CurrentStep,
105
&CurrentRank,
106
&CurrentVertex,
107
&InRankData[0], &InRankData[1], &InRankData[2]);
108
if
(ReadCount!=6)
continue
;
109
CurrentStep--;
//The input is 1 indexed, the code 0 indexed.
110
111
if
((*Data)[CurrentStep].size() <= CurrentRank)
112
{
113
(*Data)[CurrentStep].resize(CurrentRank+1);
114
}
115
116
if
((*Data)[CurrentStep][CurrentRank].size() <= CurrentVertex)
117
{
118
(*Data)[CurrentStep][CurrentRank].resize(CurrentVertex+1);
119
}
120
121
(*Data)[CurrentStep][CurrentRank][CurrentVertex].resize(Dimension);
122
(*Data)[CurrentStep][CurrentRank][CurrentVertex][0] = InRankData[0];
123
(*Data)[CurrentStep][CurrentRank][CurrentVertex][1] = InRankData[1];
124
(*Data)[CurrentStep][CurrentRank][CurrentVertex][2] = InRankData[2];
125
126
//printf("IN: %s", Line);
127
//printf("ME: [%4d,%03d,%02d] Result Vertex: %10.6f %10.6f %10.6f\n",
128
// CurrentStep+1,
129
// CurrentRank,
130
// CurrentVertex,
131
// InRankData[0], InRankData[1], InRankData[2]);
132
}
133
fclose(File);
134
return
Data;
135
}
136
137
// return 0 on difference and >1 if same
138
int
CompareTests
(
vector4d
* Test1,
vector4d
* Test2)
139
{
140
double
MaximumDifference = 0;
141
142
if
(Test1->size() != Test2->size()){
143
printf(
"Different number of steps: %lu %lu\n"
, Test1->size(), Test2->size());
144
return
0;
145
}
146
147
for
(
size_t
CurrentStep=0; CurrentStep<(*Test1).size(); ++CurrentStep)
148
{
149
if
((*Test1)[CurrentStep].size() != (*Test2)[CurrentStep].size()){
150
printf(
"Different number of ranks in Step %lu: %lu %lu\n"
, CurrentStep,(*Test1)[CurrentStep].size(),(*Test2)[CurrentStep].size());
151
return
0;
152
}
153
154
for
(
size_t
CurrentRank=0; CurrentRank<(*Test1)[CurrentStep].size(); ++CurrentRank)
155
{
156
if
((*Test1)[CurrentStep][CurrentRank].size() != (*Test2)[CurrentStep][CurrentRank].size()){
157
printf(
"Different number of vertices in Step %lu and Rank %lu: %lu %lu\n"
,CurrentStep,CurrentRank,(*Test1)[CurrentStep][CurrentRank].size(),(*Test2)[CurrentStep][CurrentRank].size());
158
return
0;
159
}
160
for
(
size_t
CurrentVertex=0; CurrentVertex<(*Test1)[CurrentStep][CurrentRank].size(); ++CurrentVertex)
161
{
162
for
(
size_t
i=0; i<(*Test1)[CurrentStep][CurrentRank][CurrentVertex].size(); ++i)
163
{
164
double
Value1 = (*Test1)[CurrentStep][CurrentRank][CurrentVertex][i];
165
double
Value2 = (*Test2)[CurrentStep][CurrentRank][CurrentVertex][i];
166
double
AbsVal = fabs(Value1-Value2);
167
MaximumDifference = MaximumDifference>AbsVal?MaximumDifference:AbsVal;
168
if
(AbsVal>0.001) printf(
"Found deviation of %g at Step: %lu Rank: %lu Vertex: %lu, between %g and %g\n"
,
169
AbsVal,
170
CurrentStep,
171
CurrentRank,
172
CurrentVertex,
173
Value1, Value2);
174
}
175
}
176
}
177
}
178
printf(
"MaximumDifference: %g\n"
, MaximumDifference);
179
return
MaximumDifference<0.001;
180
}
181
182
int
main
(
int
argc,
char
**argv)
183
{
184
if
(argc<3)
185
{
186
printf(
"Usage: %s KNOWN_GOOD TEST_OUTPUT\n"
, argv[0]);
187
return
EXIT_FAILURE;
188
}
189
char
*GoodFileName = argv[1];
190
char
*TestFileName = argv[2];
191
192
// TestData2[Step][Rank][Vertex][Dimension]
193
vector4d
* GoodData =
LoadTest
(GoodFileName);
194
vector4d
* TestData =
LoadTest
(TestFileName);
195
196
int
Matches =
CompareTests
(GoodData, TestData);
197
198
if
(Matches)
199
return
EXIT_SUCCESS;
200
else
201
return
EXIT_NOMATCH
;
202
}
main
int main(int argc, char **argv)
Definition
TestCompare.cpp:182
vector4d
std::vector< std::vector< std::vector< std::vector< double > > > > vector4d
Definition
TestCompare.cpp:43
CompareTests
int CompareTests(vector4d *Test1, vector4d *Test2)
Definition
TestCompare.cpp:138
LoadTest
vector4d * LoadTest(char *FileName)
Definition
TestCompare.cpp:55
EXIT_NOMATCH
#define EXIT_NOMATCH
Definition
TestCompare.cpp:41
tests
feature
TestCompare.cpp
Generated by
1.17.0