-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautograder.cpp
More file actions
126 lines (104 loc) · 3.25 KB
/
autograder.cpp
File metadata and controls
126 lines (104 loc) · 3.25 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
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <math.h>
#include <string.h>
#include "common.h"
#define MAX_ENTRIES 100
//
// benchmarking program
//
int main( int argc, char **argv )
{
int n[MAX_ENTRIES],i,count=0,num,p[MAX_ENTRIES];
double t[MAX_ENTRIES],slope[MAX_ENTRIES-1],ss[MAX_ENTRIES],sse[MAX_ENTRIES],ws[MAX_ENTRIES],sse_avg,ws_avg;
double lt[MAX_ENTRIES],ln[MAX_ENTRIES],b2,sx=0.0,sx2=0.0,sxy=0.0,sy=0.0;
if( find_option( argc, argv, "-h" ) >= 0 )
{
printf( "Options:\n" );
printf( "-h to see this help \n" );
printf( "-s <filename> to specify name of summary file \n");
printf( "-v to specify what to autograde (serial,pthreads,openmp,mpi) \n" );
return 0;
}
char *savename = read_string( argc, argv, "-s", NULL );
FILE *fread = savename ? fopen( savename, "r" ) : NULL;
char *autoname = read_string( argc, argv, "-v", NULL );
if (strcmp(autoname,"serial")==0){
if(fread)
while( fscanf (fread,"%d %lf",&n[count],&t[count]) != EOF )
count++;
for (i=0; i<count-1;i++) {
slope [i] = ( log(t[i+1]) - log(t[i]) ) / ( log(n[i+1]*1.0) - log(n[i]*1.0) );
}
for (i=0; i<count; i++) {
lt[i] = log(t[i]);
ln[i] = log(n[i]*1.0);
}
for (i=0; i<count; i++) {
sx += ln[i];
sy += lt[i];
sxy += ln[i]*lt[i];
sx2 += ln[i]*ln[i];
}
b2 = (sxy - (sx * sy)/ (count * 1.0) ) / (sx2 - (sx * sx)/ (count * 1.0));
printf("\nSerial code is O(N^slope)");
printf("\nSlope estimates are :");
for (i=0; i<count-1; i++){
printf(" %lf",slope[i]);
}
printf("\nSlope estimate for line fit is: %lf\n", b2);
printf("\n\n");
}
if (strcmp(autoname,"pthreads")==0 || strcmp(autoname,"openmp")==0 || strcmp(autoname,"mpi")==0){
if(fread){
fscanf (fread,"%d %lf",&n[count],&t[count]);
count++; p[0]=1;
while( fscanf (fread,"%d %d %lf",&n[count],&p[count],&t[count]) != EOF )
count++;
}
num = count/2;
ss[0] = sse[0] = ws[0] = t[0]/t[1];
for (i=2; i<=num;i++) {
ss[i-1] = t[0]/t[i];
sse[i-1] = ss[i-1]/p[i];
ws[i-1] = t[0]/t[i+num-1];
}
printf("\nStrong scaling estimates are :\n");
for (i=0; i<num; i++){
printf(" %7.2lf",ss[i]);
}
printf(" (speedup)\n");
for (i=0; i<num; i++){
printf(" %7.2lf",sse[i]);
}
printf(" (efficiency) for\n");
for (i=0; i<num; i++){
printf(" %7d",p[i+1]);
}
printf(" threads/processors\n\n");
sse_avg=0.0;
for (i=0; i<num; i++){
sse_avg+=sse[i];
}
sse_avg/=num;
printf("Average strong scaling efficiency: %7.2lf \n\n",sse_avg);
printf("Weak scaling estimates are :\n");
for (i=0; i<num; i++){
printf(" %7.2lf",ws[i]);
}
printf(" (efficiency) for\n");
for (i=0; i<num; i++){
printf(" %7d",p[i+1]);
}
printf(" threads/processors\n\n");
ws_avg=0.0;
for (i=0; i<num; i++){
ws_avg+=ws[i];
}
ws_avg/=num;
printf("Average weak scaling efficiency: %7.2lf \n\n",ws_avg);
}
fclose( fread );
return 0;
}