-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathclient.cpp
More file actions
201 lines (176 loc) · 5.39 KB
/
client.cpp
File metadata and controls
201 lines (176 loc) · 5.39 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
#include "../utils/utils.hh"
#include "../utils/TimeStamp.hh"
#include "../utils/StatVector.hh"
#include "tcp_utils.hh"
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <iostream>
#include <fstream>
enum client_flag_enum {CGWIN_ON, CGWIN_OFF};
enum client_flag_enum gl_client_flag = CGWIN_OFF;
void cmd2str(const char*cmd, char *s){
FILE* pipe = popen(cmd, "r");
fscanf(pipe, "%s", s);
pclose(pipe);
}
/*
* Sends series[0..n-1].
* Receives psum[0..n-1] (partial sums of above).
* Transmission in blocks of size blocksize.
* Assumes n divisible by blocksize.
* stat_ns --> number of sends per block.
* star_nr --> number of recvs per block.
* stat_ts --> cycles per block sent.
* stat_tr --> cycles per block rcvd.
*/
void partialsum_client(int sock2server,
double *series, int n,
int blocksize,
double *psum,
StatVector& stat_ns,
StatVector& stat_nr,
StatVector& stat_ts,
StatVector& stat_tr){
assrt(gl_init_cgwin == 1);
int count = n/blocksize;
assrt(n%blocksize == 0);
double cycles;
TimeStamp clk;
for(int i=0; i < count; i++){
clk.tic();
int nsend;
switch(gl_client_flag){
case CGWIN_OFF:
nsend=block_send(sock2server, series, 8*blocksize);
break;
case CGWIN_ON:
nsend=block_send_cgw(sock2server, series, 8*blocksize,
gl_cgwin);
break;
}
cycles = clk.toc();
stat_ns.insert((double)nsend);
stat_ts.insert((double)cycles);
clk.tic();
int nrecv=block_recv(sock2server, psum, 8*blocksize);
cycles = clk.toc();
stat_nr.insert((double)nrecv);
stat_tr.insert((double)cycles);
series += blocksize;
psum += blocksize;
}
close(sock2server);
}
void client(const char *server, int blocksize, int n){
assrt(n%blocksize == 0);
double *series= new double[n];
for(int i=0; i < n; i++)
series[i] = (i%2==0)?4.0/(2*i+1):-4.0/(2*i+1);
double *psum=new double[n];
int count = n/blocksize;
StatVector stat_ns(count), stat_nr(count),
stat_ts(count), stat_tr(count);
std::cout<<"client: connecting to server "<<server<<std::endl;
int sock2server = connect2server(server, PORTNUM);
std::cout<<"client: transmitting series to server "<<std::endl;
TimeStamp clk;
clk.tic();
partialsum_client(sock2server, series, n, blocksize, psum,
stat_ns, stat_nr, stat_ts, stat_tr);
double cycles = clk.toc();
std::cout<<"client: done sending series & recving partial sums"
<<std::endl;
/*
* Outputs information about partial sum service.
*/
double CPUGHZ = gl_cgwin.CPUGHZ;
char fname[200];
char cmd[200];
char str[200];
cmd2str("date '+%m_%d_%y_h%H'", str);
sprintf(fname,"output/tcpip_%s.txt", str);
sprintf(cmd, "uname -n >> %s", fname);
system(cmd);
std::cout<<"client: output sent to "<<fname<<std::endl;
std::ofstream ofile(fname, std::ios::app);
if(gl_client_flag == CGWIN_ON)
ofile<<"blocks broken up to collect cgwin time series"
<<std::endl;
ofile<<"series size(n) = "<<n*1.0<<std::endl;
ofile<<" blksize = "<<blocksize*1.0<<std::endl;
ofile<<" pi = "<<psum[n-1]<<std::endl;
ofile<<" error = "<<3.141592653589793238462643383-psum[n-1]
<<std::endl;
ofile<<" nsend/block = "<<stat_ns.median()<<std::endl;
ofile<<" nrecv/block = "<<stat_nr.median()<<std::endl;
ofile<<" send ms/block = "<<stat_ts.median()/(1e9*CPUGHZ)*1e3
<<" ms"<<std::endl;
ofile<<" recv ms/block = "<<stat_tr.median()/(1e9*CPUGHZ)*1e3
<<" ms"<<std::endl;
ofile<<" bandwidth = "<<16.0*n/cycles*1e9*CPUGHZ/1e3<<" kbps"
<<std::endl;
for(int i=0; i < 70; i++)
ofile<<"-";
ofile<<std::endl;
ofile.close();
std::cout<<"client: bandwidth = "<<16.0*n/cycles*1e9*CPUGHZ/1e3<<" kbps"
<<std::endl;
delete[] series;
delete[] psum;
}
void output_cgwin(double *t, int *cgwin, int len){
std::cout<<"client: output cgwin info to output/cgwin.dat"<<std::endl;
FILE *fptr;
fptr = fopen("output/cgwin.dat", "w");
for(int i=0; i < len; i++)
fprintf(fptr, "\t%8.3e \t\t %d \n", t[i], cgwin[i]);
fclose(fptr);
}
int main(){
char server[200];
std::cout<<"client: cut and past server address: ";
std::cin>>server;
std::cout<<"client: will connect to "<<server<<std::endl;
std::cout<<"client: CPUGHZ of HP a6400z = 1.8 "<<std::endl;
std::cout<<"client: CPUGHZ of HP Z200 = 3.4 "<<std::endl;
std::cout<<"client: CPUGHZ of screms = 2.6 "<<std::endl;
std::cout<<"client: CPUGHZ of lonestar = 3.3 "<<std::endl;
std::cout<<"client: CPUGHZ of stampede = 2.7 "<<std::endl;
std::cout<<"client: input client CPUGHZ = ";
double cpughz;
std::cin>>cpughz;
std::cout<<std::endl;
int tmp;
std::cout<<"client: input 1 to keep track of cgwin, 0 otherwise"
<<std::endl;
std::cout<<"client: keep track of cgwin? ";
std::cin>>tmp;
std::cout<<std::endl;
if(tmp == 1){
gl_client_flag = CGWIN_ON;
std::cout<<"client: setting cgwin time series "
"to max of 10^6 entries"<<std::endl;
init_cgwin(1000*1000, cpughz);
}
else{
gl_client_flag = CGWIN_OFF;
init_cgwin(1, cpughz);
}
int blocksize;
std::cout<<"client: blocksize must be same as on server"<<std::endl;
std::cout<<"client: blocksize = ";
std::cin>>blocksize;
std::cout<<std::endl;
assrt(blocksize > 0);
int n;
std::cout<<"client number of blocks = ";
std::cin>>n;
std::cout<<std::endl;
assrt(n > 0);
n = n*blocksize; //Number of terms in series.
client(server, blocksize, n);
if(gl_client_flag == CGWIN_ON)
output_cgwin(gl_cgwin.t, gl_cgwin.cgw, gl_cgwin.indx);
exit_cgwin();
}