9 #define MAX_SIZE 131072
13 void getclockvalue(double *retval
)
16 static long zusec
= 0;
20 gettimeofday(&tp
, &tzp
);
22 if ( zsec
== 0 ) zsec
= tp
.tv_sec
;
23 if ( zusec
== 0 ) zusec
= tp
.tv_usec
;
25 *retval
= (tp
.tv_sec
- zsec
) + (tp
.tv_usec
- zusec
) * 0.000001 ;
29 int main(int argc
, char **argv
)
31 int myid
, root
, numprocs
, i
, j
, k
, size
, num_sizes
, times
,reps
;
32 double startwtime
, endwtime
, opertime
[NUMTIMES
][NUM_SIZES
];
33 double mean
[NUM_SIZES
],min
[NUM_SIZES
],max
[NUM_SIZES
];
35 char processor_name
[MPI_MAX_PROCESSOR_NAME
];
38 int msgsizes
[NUM_SIZES
];
50 MPI_Init(&argc
,&argv
);
51 MPI_Comm_size(MPI_COMM_WORLD
,&numprocs
);
52 MPI_Comm_rank(MPI_COMM_WORLD
,&myid
);
53 MPI_Get_processor_name(processor_name
,&namelen
);
56 fprintf(stdout
,"Process %d of %d on %s \n",
57 myid
, numprocs
, processor_name
);
60 /* Initialize memory buffers */
62 sendb
= (int *)malloc(MAX_SIZE
*sizeof(int)*numprocs
);
63 recvb
= (int *)malloc(MAX_SIZE
*sizeof(int)*numprocs
);
66 startwtime
= MPI_Wtime();
68 getclockvalue (&startwtime
);
69 getclockvalue (&endwtime
);
72 MPI_Barrier(MPI_COMM_WORLD
);
74 for (i
=0; i
<NUMTIMES
; i
++)
76 for (num_sizes
=0; num_sizes
<NUM_SIZES
; num_sizes
++) {
77 size
= msgsizes
[num_sizes
];
78 for (j
=0; j
<size
*numprocs
; j
++) {
82 MPI_Alltoall(sendb
,size
,MPI_INT
,recvb
,size
,MPI_INT
,MPI_COMM_WORLD
);
83 MPI_Barrier(MPI_COMM_WORLD
);
85 startwtime
= MPI_Wtime();
87 getclockvalue (&startwtime
);
89 for (k
=0; k
< REPS
; k
++) {
90 MPI_Alltoall(sendb
,size
,MPI_INT
,recvb
,size
,MPI_INT
,MPI_COMM_WORLD
);
93 endwtime
= MPI_Wtime();
95 getclockvalue (&endwtime
);
97 opertime
[i
][num_sizes
] =
98 (endwtime
-startwtime
)/(float)(REPS
) ;
101 MPI_Barrier(MPI_COMM_WORLD
);
105 for (num_sizes
=0; num_sizes
< NUM_SIZES
; num_sizes
++) {
106 mean
[num_sizes
] = 0.0;
107 min
[num_sizes
] = 100000. ;
108 max
[num_sizes
] = 0.0 ;
111 for (i
=0; i
<NUMTIMES
; i
++) {
112 for (num_sizes
=0; num_sizes
< NUM_SIZES
; num_sizes
++) {
114 printf("%d %d %g\n",i
,msgsizes
[num_sizes
],
115 opertime
[i
][num_sizes
]) ;
117 mean
[num_sizes
] += opertime
[i
][num_sizes
] ;
118 if (min
[num_sizes
] > opertime
[i
][num_sizes
])
119 min
[num_sizes
] = opertime
[i
][num_sizes
] ;
120 if (max
[num_sizes
] < opertime
[i
][num_sizes
])
121 max
[num_sizes
] = opertime
[i
][num_sizes
] ;
128 for (num_sizes
=0; num_sizes
< NUM_SIZES
; num_sizes
++)
129 mean
[num_sizes
] /= (float)NUMTIMES
;
132 for (num_sizes
=0; num_sizes
< NUM_SIZES
; num_sizes
++) {
133 printf("%d %g %g %g\n",msgsizes
[num_sizes
],mean
[num_sizes
] * 1000000.,
134 min
[num_sizes
] * 1000000., max
[num_sizes
] * 1000000. );
136 printf("================================================\n");
139 times
=NUMTIMES
; reps
=REPS
;
140 printf("#Alltoall: P=%d, NUMTIMES=%d, REPS=%d\n",
141 numprocs
, times
, reps
);
142 printf("%d ",numprocs
);
143 for (num_sizes
=0; num_sizes
< NUM_SIZES
; num_sizes
++)
144 printf("%g ",mean
[num_sizes
] * 1000000.);