-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathReport.cpp
More file actions
252 lines (227 loc) · 7.13 KB
/
Report.cpp
File metadata and controls
252 lines (227 loc) · 7.13 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
//
// Performs various reporting functions
//
// Do not change the code in this file, as doing so
// could cause your submission to be graded incorrectly
//
#include <iostream>
#include <fstream>
#include <iomanip>
#include <stdlib.h>
#include <math.h>
#ifdef _MPI_
#include "mpi.h"
#endif
using namespace std;
// Reports statistics about the computation
// These values should not vary (except to within roundoff)
// when we use different numbers of processes to solve the problem
void ABEND()
{
cout.flush();
cerr.flush();
#ifdef _MPI_
MPI_Abort(MPI_COMM_WORLD,-1);
#else
exit(-1);
#endif
}
void Stop(){
cout.flush();
cerr.flush();
#ifdef _MPI_
MPI_Barrier(MPI_COMM_WORLD);
MPI_Finalize();
#endif
exit(-1);
}
// Report statistics periodically
void repNorms(ofstream& logfile, double l2norm, double mx, double dt, int m,int n, int niter, int stats_freq){
int myrank;
#ifdef _MPI_
MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
#else
myrank = 0;
#endif
if (!myrank){
if ( !(niter % stats_freq)) {
cout << setw(6);
cout.setf(ios::fixed);
cout << "iteration= " << niter << ", t= ";
cout.unsetf(ios::fixed);
cout.setf(ios::scientific);
cout.precision(6);
cout << "Max norm: " << mx << ", L2norm: " << l2norm << endl;
logfile << setw(6);
logfile.setf(ios::fixed);
logfile << "iteration= " << niter << ", t= ";
logfile.unsetf(ios::fixed);
logfile.setf(ios::scientific);
logfile.precision(6);
logfile << "Max norm: " << mx << ", L2norm: " << l2norm << endl;
}
}
#ifdef _MPI_
MPI_Barrier(MPI_COMM_WORLD);
#endif
}
void printTOD(ofstream& logfile,string mesg)
{
time_t tim = time(NULL);
string s = ctime(&tim);
int myrank;
#ifdef _MPI_
MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
#else
myrank = 0;
#endif
if (!myrank){
cout << endl;
logfile << endl;
if (mesg.length() == 0) {
cout << "Time of day: " << s.substr(0,s.length()-1) << endl;
logfile << "Time of day: " << s.substr(0,s.length()-1) << endl;
}
else {
cout << "[" << mesg << "] " ;
cout << s.substr(0,s.length()-1) << endl;
logfile << "[" << mesg << "] " ;
logfile << s.substr(0,s.length()-1) << endl;
}
cout << endl;
logfile << endl;
}
#ifdef _MPI_
MPI_Barrier(MPI_COMM_WORLD);
#endif
}
// Computes the gigaflops rate
double gflops(int n, int niter, double time){
int n2 = n*n;
int64_t updates = (int64_t) n2 * (int64_t) niter;
int64_t flops = 28 * updates;
double flop_rate = (double) flops / time;
return ( flop_rate/1.0e9);
}
void ReportEnd(ofstream& logfile, int niters, double l2norm, double mx, int m,int n, double t0, int px, int py, bool noComm){
printTOD(logfile,"Simulation completes");
int myrank;
#ifdef _MPI_
MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
#else
myrank = 0;
#endif
if (!myrank){
double gf = gflops(n+1, niters, t0);
cout << "End at";
cout << setw(6);
cout.setf(ios::fixed);
cout << " iteration " << niters << endl;
cout.unsetf(ios::fixed);
cout.setf(ios::scientific);
cout.precision(6);
cout << "Max norm: " << mx << ", L2norm: " << l2norm << endl;
cout.unsetf(ios::scientific);
cout.unsetf(ios::fixed);
cout.precision(6);
cout << "Running Time: " << t0 << " sec." << endl;
cout.precision(3);
cout << "GFlop rate: " << gf << endl << endl;
cout << " M x N [px x py] {C?} [#iter] {T_p, Gflops} Linf, L2" << endl;
// This should really print out m and n, but
// we had to add 1 to be consistent with the reference output
cout << "@ " << m+1 << " " << n+1 << " ";
cout.precision(3);
cout << "[" << px << " " << py << "] ";
cout << " ";
if (!noComm)
cout << "{Y}";
else
cout << "{N}";
cout.precision(6);
cout << "\t[ " << niters << "] ";
cout.precision(4);
// cout << t0 << " " << gf << " ";
cout << "{" << t0 << " " << gf << "} ";
cout.unsetf(ios::fixed);
cout.setf(ios::scientific);
cout.precision(5);
cout << mx << " " << l2norm << endl;
cout << " -----" << endl;
logfile << "End at";
logfile << setw(6);
logfile.setf(ios::fixed);
logfile << " iteration " << niters << endl;
logfile.unsetf(ios::fixed);
logfile.setf(ios::scientific);
logfile.precision(5);
logfile << "Max norm: " << mx << ", L2norm: " << l2norm << endl;
logfile.unsetf(ios::scientific);
logfile.unsetf(ios::fixed);
logfile.precision(6);
logfile << "Running Time: " << t0 << " sec." << endl;
logfile << "{" << t0 << " " << gf << "} ";
logfile.precision(3);
logfile << "GFlop rate: " << gf << endl << endl;
logfile.precision(5);
logfile << " M x N [px x py] {C?} [#iter] {T_p, Gflops} Linf, L2" << endl;
logfile << "@ " << m << " " << n << " ";
logfile.precision(3);
logfile << "[" << px << " " << py << "] ";
logfile << " ";
if (!noComm)
logfile << "{Y}";
else
logfile << "{N}";
logfile.precision(6);
logfile << "\t[ " << niters << "] ";
logfile.precision(4);
logfile << "{t0" << " " << gf << "} ";
logfile.unsetf(ios::fixed);
logfile.setf(ios::scientific);
logfile.precision(5);
logfile << mx << " " << l2norm << endl;
logfile << " -----" << endl;
}
#ifdef _MPI_
MPI_Barrier(MPI_COMM_WORLD);
#endif
}
void ReportStart(ofstream& logfile,double dt, int niters, int m, int n, int px, int py, bool noComm){
int myrank;
#ifdef _MPI_
MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
#else
myrank = 0;
#endif
if (!myrank){
cout << "dt= " << dt << ", ";
cout << "# iters = " << niters << endl;
// This should really print out m and n, but
// we had to add 1 to be consistent with the reference output
cout << "m x n = " << m+1 << " x " << n+1 << endl;
cout << "processor geometry: " << px << " x " << py << endl;
cout << endl;
logfile << "dt= " << dt << ", ";
logfile << "# iters = " << niters << endl;
// This should really print out m and n, but
// we had to add 1 to be consistent with the reference output
logfile << "m x n = " << m+1 << " x " << n+1 << endl;
logfile << "processor geometry: " << px << " x " << py << endl;
logfile << endl;
#ifdef _MPI_
cout << "Compiled with MPI ENabled\n";
logfile << "Compiled with MPI ENabled\n";
if (noComm){
cout << "Communication shut off" << endl;
logfile << "Communication shut off" << endl;
}
#else
cout << "Compiled with MPI DISabled\n";
logfile << "Compiled with MPI DISabled\n";
#endif
}
#ifdef _MPI_
MPI_Barrier(MPI_COMM_WORLD);
#endif
}