-
Notifications
You must be signed in to change notification settings - Fork 0
/
NoiseFinder.c
227 lines (190 loc) · 6.79 KB
/
NoiseFinder.c
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
/** \file NoiseFinder.c
* Author: Abhinav S Bhatele (bhatelele@illinois.edu)
* Previous contributors: Authors: Eric Bohm, Chee Wai L
*
* A simple benchmark to quantify computational noise
*/
#include <mpi.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#define UNIT_WORK_FACTOR 10000
#define TAG 255
#define NUMBINS 200
int doUnitWork(int);
int main(int argc, char **argv) {
int myrank, size;
int i, j, pos;
int iterations = 100;
int iterationsOuter;
int worksize;
/* Statistics data */
double sum = 0.0;
double sum_of_squares = 0.0;
double min = 0.0;
double max = 0.0;
double globalmin = 0.0;
double globalmax = 0.0;
double mean = 0.0;
double variance = 0.0;
double stddev = 0.0;
long long smallHist[NUMBINS+1]; /* 5 us each */
long long smallHistSum[NUMBINS+1];
long long largeHist[NUMBINS+1]; /* 5 ms each */
long long largeHistSum[NUMBINS+1];
for(i=0; i<NUMBINS+1; i++) {
smallHist[i] = 0;
smallHistSum[i] = 0;
largeHist[i] = 0;
largeHistSum[i] = 0;
}
/* used to prevent the compiler from optimizing the delay loop away */
double dummydata = 0.0;
/* Timing related variables */
double prevtime, currtime, intime = 0.0;
double overhead = 0.0;
double prevouterttime, outtime;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
long long noiseProcHist[size];
long long noiseProcHistCat[size];
for (i = 0; i < size; i++){
noiseProcHist[i] = 0;
noiseProcHistCat[i] = 0;
}
int errlen;
char usage[100+MPI_MAX_ERROR_STRING]="Usage: NoiseFinder NumIterations Grainsize\n";
if(argc<3) {
printf(usage);
fflush(stdout);
MPI_Abort(MPI_COMM_WORLD,10);
}
iterationsOuter = atoi(argv[1]);
worksize = atoi(argv[2]);
double *savetime = malloc(sizeof(double)*iterationsOuter*iterations);
/* Walltime overheads */
prevtime = MPI_Wtime();
for (i=0; i<1000; i++) {
MPI_Wtime();
}
overhead = (MPI_Wtime() - prevtime)/1000;
int donework = 0;
struct valpair {
double val;
int rank;
} oneminp, onemaxp, *minpair, *maxpair, maxdevpair, *outminpair, *outmaxpair;
minpair = (struct valpair *) malloc (iterationsOuter * sizeof(struct valpair));
maxpair = (struct valpair *) malloc (iterationsOuter * sizeof(struct valpair));
outminpair = (struct valpair *) malloc (iterationsOuter * sizeof(struct valpair));
outmaxpair = (struct valpair *) malloc (iterationsOuter * sizeof(struct valpair));
prevouterttime = MPI_Wtime();
globalmin = prevouterttime*1000;
globalmax = 0.0;
for(j=0; j<iterationsOuter; j++) {
prevtime = MPI_Wtime();
min = prevtime*1000.0;
max = 0.0;
/* outtime = 0.0; */
for(i=0; i<iterations; i++) {
prevtime = MPI_Wtime();
donework = doUnitWork(worksize);
currtime = MPI_Wtime();
intime = currtime - prevtime;
savetime[j*iterations + i] = intime;
/* outtime += intime; */
sum += intime;
sum_of_squares += intime * intime;
min = (min > intime) ? intime : min;
max = (max < intime) ? intime : max;
globalmin = (globalmin > intime) ? intime : globalmin;
globalmax = (globalmax < intime) ? intime : globalmax;
pos = (int) (intime / 0.000005); /* size of each bin = 5 us */
if(pos < NUMBINS)
smallHist[pos]++;
else
smallHist[NUMBINS]++;
pos = (int) (intime / 0.005); /* size of each bin = 5 ms */
if(pos < NUMBINS)
largeHist[pos]++;
else
largeHist[NUMBINS]++;
}
outtime = currtime - prevouterttime;
prevouterttime = currtime;
oneminp.val = min;
oneminp.rank = myrank;
onemaxp.val = max;
onemaxp.rank = myrank;
MPI_Allreduce(&oneminp, &minpair[j], 1, MPI_DOUBLE_INT, MPI_MINLOC, MPI_COMM_WORLD);
MPI_Allreduce(&onemaxp, &maxpair[j], 1, MPI_DOUBLE_INT, MPI_MAXLOC, MPI_COMM_WORLD);
oneminp.val = outtime;
oneminp.rank = myrank;
onemaxp.val = outtime;
onemaxp.rank = myrank;
MPI_Allreduce(&oneminp, &outminpair[j], 1, MPI_DOUBLE_INT, MPI_MINLOC, MPI_COMM_WORLD);
MPI_Allreduce(&onemaxp, &outmaxpair[j], 1, MPI_DOUBLE_INT, MPI_MAXLOC, MPI_COMM_WORLD);
/* Barrier is pretty redundant
MPI_Barrier(MPI_COMM_WORLD); */
}
/* Compute Statistics */
mean = sum/(iterationsOuter*iterations);
stddev = sqrt((sum_of_squares - 2*mean*sum + mean*mean*iterationsOuter*iterations) /
(iterationsOuter*iterations - 1));
onemaxp.val=stddev;
MPI_Allreduce(&onemaxp, &maxdevpair, 1, MPI_DOUBLE_INT, MPI_MAXLOC, MPI_COMM_WORLD);
noiseProcHist[myrank] = smallHist[NUMBINS];
MPI_Reduce(&noiseProcHist, &noiseProcHistCat, size, MPI_LONG_LONG, MPI_SUM, 0, MPI_COMM_WORLD);
MPI_Reduce(&smallHist, &smallHistSum, NUMBINS+1, MPI_LONG_LONG, MPI_SUM, 0, MPI_COMM_WORLD);
MPI_Reduce(&largeHist, &largeHistSum, NUMBINS+1, MPI_LONG_LONG, MPI_SUM, 0, MPI_COMM_WORLD);
/* Print Summary */
char name[30];
sprintf(name, "noise_pe%d", myrank);
FILE *outf = fopen(name, "w");
fprintf(outf, "Rank %d : Mean = %f Min = %f Max = %f StdDev = %f\n", myrank, mean, globalmin, globalmax, stddev);
for(i=0; i<iterationsOuter*iterations; i++)
fprintf(outf, "Rank %d: Time %f\n", myrank, savetime[i]);
fflush(NULL);
fclose(outf);
if(myrank==0)
{ /** so the compiler can't wish away your work */
printf("donework %d\n", donework);
}
fflush(NULL);
MPI_Barrier(MPI_COMM_WORLD);
if(myrank==0) {
FILE *outs = fopen("summary", "w");
fprintf(outs, "Rank %d : Num Steps = %d X %d\n", myrank, iterationsOuter, iterations);
fprintf(outs, "Rank %d : MPI_Wtime overhead per step = %f\n", myrank, overhead);
fprintf(outs, "Rank %d : worksize %d\n", myrank, worksize);
for(i=0;i<iterations; i++)
fprintf(outs, "Iter[%d] max %f on rank %d min %f on rank %d\n", i, maxpair[i].val, maxpair[i].rank, minpair[i].val, minpair[i].rank);
for(i=0;i<iterationsOuter; i++)
fprintf(outs, "Iter[%d] outer max %f on rank %d min %f on rank %d\n", i, outmaxpair[i].val, outmaxpair[i].rank, outminpair[i].val, outminpair[i].rank);
fprintf(outs, "Rank[%d] had max dev %f \n", maxdevpair.rank, maxdevpair.val);
for(i=0; i<NUMBINS+1; i++)
fprintf(outs, "smallHist %d %lld\n", i, smallHistSum[i]);
for(i=0; i<NUMBINS+1; i++)
fprintf(outs, "largeHist %d %lld\n", i, largeHistSum[i]);
for(i=0; i<size; i++)
fprintf(outs, "noiseProcHist %d %lld\n", i, noiseProcHistCat[i]);
fclose(outs);
}
/*
printf("Rank %d : Average steptime = %f\n", myrank, mean);
printf("Rank %d : donework %d\n",myrank, donework);
*/
fflush(stdout);
MPI_Barrier(MPI_COMM_WORLD);
MPI_Finalize();
}
int doUnitWork(int repeat) {
double dummydata = 0.0;
int i, repeatcount;
for (repeatcount=0; repeatcount<repeat; repeatcount++) {
for (i=0; i<UNIT_WORK_FACTOR; i++) {
dummydata += i*repeatcount;
}
}
return (((int)dummydata)*repeat);
}