-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_mpi_t_barrier.c
48 lines (40 loc) · 1.02 KB
/
test_mpi_t_barrier.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
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <mpi.h>
#include <math.h>
#include <sys/time.h>
#include "mpibarrier.h"
double timeduration(struct timeval t1, struct timeval t2)
{
return (t2.tv_sec-t1.tv_sec)*1000000+(t2.tv_usec-t1.tv_usec);
}
int main(int argc, char **argv)
{
int iterations, rank;
int numberofprocess;
MPI_Init(&argc, &argv);
if (argc >=2) {
iterations = atoi(argv[1]);
}
else {
printf("usage: test numberofiterations");
return 0;
}
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &numberofprocess);
int max_round = ceil(log(numberofprocess) / log(2));
int j;
struct timeval t1, t2;
double duration=0.0;
//printf("process %d is working\n", rank);
gettimeofday(&t1,NULL);
for (j=0; j<iterations; j++) {
tournament_barrier(rank, numberofprocess, max_round);
}
gettimeofday(&t2,NULL);
duration = timeduration(t1,t2);
printf("average time in %d rounds on %d process is %f\n", iterations, rank, duration);
MPI_Finalize();
return 0;
}