forked from telmin/lu2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpiperftest.c
230 lines (211 loc) · 5.46 KB
/
mpiperftest.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
227
228
229
230
/*
* MPITEST.C
*
* Copyright J. Makino March 2 2001
*
* JM's very first MPI program....
*/
#include "mpi.h"
#include <stdio.h>
#include <math.h>
#include "lu2_mp.h"
#ifndef MPI
#define MPI
#endif
#ifdef TCPLIB
#include "tcplib.h"
#endif
#define MAXBUFSIZE 5000000
MPI_Status status;
double sendbuffer[MAXBUFSIZE];
double receivebuffer[MAXBUFSIZE];
void sendbuf(int size, int dest)
{
MPI_Send( &sendbuffer, size, MPI_DOUBLE, dest, 0, MPI_COMM_WORLD);
}
void receivebuf(int size, int source)
{
MPI_Recv( &receivebuffer, size, MPI_DOUBLE, source, 0,
MPI_COMM_WORLD, &status);
}
void initbuf(int size)
{
int i;
for (i=0;i<size;i++){
sendbuffer[i] = i;
receivebuffer[i]=99999;
}
}
double f(double);
double f(double a)
{
return (4.0 / (1.0 + a*a));
}
int main(int argc,char *argv[])
{
int done = 0, n, myid, numprocs, i;
int ringmax, interval;
double PI25DT = 3.141592653589793238462643;
double mypi, pi, h, sum, x;
double startwtime = 0.0, endwtime;
int namelen;
char processor_name[MPI_MAX_PROCESSOR_NAME];
int size, count, ic;
int left, right, myoffset,level;
// MPI_Init(&argc,&argv);
int retval;
// MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &retval);
MP_initialize(&argc,&argv);init_current_time();
fprintf(stderr,"thred val=%d\n", retval);
MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
MPI_Comm_rank(MPI_COMM_WORLD,&myid);
MPI_Get_processor_name(processor_name,&namelen);
ringmax = 4;
if (ringmax > numprocs) ringmax = numprocs;
fprintf(stdout,"Process %d of %d on %s\n",
myid, numprocs, processor_name);
if (numprocs == 1){
fprintf(stderr,"I have only one procesor... nothing to do\n");
MPI_Finalize();
return 0;
}
n = 0;
interval = numprocs/ringmax;
left = (myid-interval+numprocs)%numprocs;
right = (myid+interval) %numprocs;
fprintf(stderr,"Myid, R, L= %d %d %d\n",myid,right,left);
#ifdef TCPLIB
tcp_request_full_MPI_connection();
#endif
#define SIZEMAX 5000000
#define COUNTMAX 2000
#define TOTALMAX 6e6
count = COUNTMAX;
if ( myid == 0){
startwtime = MPI_Wtime();
}
for(ic=0;ic<count;ic++){
MPI_Barrier(MPI_COMM_WORLD);
}
if (myid == 0){
double dtime;
endwtime = MPI_Wtime();
dtime = endwtime - startwtime;
printf("Barrier count = %d wall clock time = %f %f us/synch\n",
count, dtime, (dtime*1e6)/count);
}
if ( myid == 0){
startwtime = MPI_Wtime();
}
for(ic=0;ic<count;ic++){
double ttmp = myid;
double global_tmin;
MPI_Allreduce(&ttmp, &global_tmin,1, MPI_DOUBLE, MPI_MIN,MPI_COMM_WORLD);
}
if (myid == 0){
double dtime;
endwtime = MPI_Wtime();
dtime = endwtime - startwtime;
printf("Allreduce count = %d wall clock time = %f %f us/call\n",
count, dtime, (dtime*1e6)/count);
}
#ifdef TCPLIB
for(level = 2; level <= numprocs; level*=2){
if ( myid == 0){
startwtime = MPI_Wtime();
}
for(ic=0;ic<count;ic++){
tcp_barrier(level);
}
tcp_barrier(numprocs);
if (myid == 0){
double dtime;
endwtime = MPI_Wtime();
dtime = endwtime - startwtime;
printf("TCP Barrier level %d count = %d wall clock time = %f %f us/synch\n",
level,count, dtime, (dtime*1e6)/count);
}
}
if ( myid == 0){
startwtime = MPI_Wtime();
}
for(ic=0;ic<count;ic++){
double ttmp = myid;
double global_tmin= tcp_allmax(ttmp);
if (global_tmin != (numprocs - 1)){
fprintf(stderr,"tcp allmax failed myid %d %d %d\n",
myid, global_tmin, numprocs);
}
}
if (myid == 0){
double dtime;
endwtime = MPI_Wtime();
dtime = endwtime - startwtime;
printf("TCP Allreduce count = %d wall clock time = %f %f us/call\n",
count, dtime, (dtime*1e6)/count);
}
#endif
for(size=1;size <= SIZEMAX; size *= 4){
int mode;
count = COUNTMAX;
#ifdef TCPLIB
#define MODEMAX 2
#define MODEMIN 0
#else
#define MODEMAX 3
#define MODEMIN 0
#endif
for(mode=MODEMIN;mode <MODEMAX;mode++){
int length = size*sizeof(double);
initbuf(size);
MPI_Barrier(MPI_COMM_WORLD);
startwtime = MPI_Wtime();
if (((double)count)*size > TOTALMAX) count = TOTALMAX/size;
for(ic=0;ic<count;ic++){
if (mode == 0){
MPI_Sendrecv(&sendbuffer,size,MPI_DOUBLE,left,0,
&receivebuffer,size,MPI_DOUBLE,right,0,
MPI_COMM_WORLD, &status);
}else if (mode == 1){
MPI_Bcast(&sendbuffer,size*8,MPI_BYTE,0,MPI_COMM_WORLD);
}else if (mode == 2){
MP_mybcast(&sendbuffer,size*8,0,MPI_COMM_WORLD);
#if 0
if ((myid/(numprocs/ringmax)%2) == 0){
/* if ((ic % 1000) == 0)fprintf(stderr,"count = %d\n", ic);*/
sendbuf(size, left);
receivebuf(size,right);
}else{
receivebuf(size,right);
sendbuf(size, left);
}
}else{
int sendparms[2];
int receiveparms[2];
sendparms[0] = length;
tcp_simd_transfer_data_by_MPIname(left,sendparms,1,sendbuffer,
right,receiveparms,receivebuffer);
#endif
}
}
if (myid == 0){
double dtime;
endwtime = MPI_Wtime();
dtime = endwtime - startwtime;
printf("size, count = %d %d wall clock time = %f %f MB/s\n",
size, count, dtime,
((double)size)*count*sizeof(double)/dtime/1e6*2);
fflush( stdout );
}else if (myid==-1){
#if 1
if (mode )
for(i=0;i<size;i+= 1+size/3){
fprintf(stderr," data[%d] = %e\n", i, receivebuffer[i]);
}
#endif
}
}
}
MPI_Finalize();
return 0;
}