110 likes | 129 Views
Timing in MPI. Tarik Booker MPI Presentation May 7, 2003. What we will cover…. How to time programs Sample Programs My Samples MPI Pi Program. How to Time Programs. Very Easy Simply use function MPI_Wtime(). MPI_Wtime(). Null input Returns a Long Float (double)
E N D
Timing in MPI Tarik Booker MPI Presentation May 7, 2003
What we will cover… • How to time programs • Sample Programs • My Samples • MPI Pi Program
How to Time Programs • Very Easy • Simply use function MPI_Wtime()
MPI_Wtime() • Null input • Returns a Long Float (double) • Not like UNIX “clock” function • MPI_Wtime() is somewhat arbitrary • Starts depending on node
How to Time Code • Must use time blocks • Start time • End time • Time for your code is simply end_time – start_time.
Example #include<stdio.h> #include<mpi.h> main(int argc, char **argv) { int size, node; double start, end; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &node); MPI_Comm_size(MPI_COMM_WORLD, &size); start = MPI_Wtime(); if(node==0) { printf(" Hello From Master. Time = %lf \n", MPI_Wtime() - start); //Count number of ticks } else { printf("Hello From Slave #%d %lf \n", node, (MPI_Wtime() - start)); } MPI_Finalize(); }
Example (2) #include<stdio.h> #include<mpi.h> main(int argc, char **argv) { int size, node; int serial_counter = 0; double start, end; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &node); MPI_Comm_size(MPI_COMM_WORLD, &size); MPI_Barrier(MPI_COMM_WORLD); start = MPI_Wtime(); MPI_Barrier(MPI_COMM_WORLD); if(node==0) { printf("Hello From Node #%d %lf \n", node, (MPI_Wtime() - start)); } else { printf("Hello From Slave #%d #%lf \n", node, (MPI_Wtime() - start)); } MPI_Finalize(); }
Pi Example • Uses MPI to compute value of Pi using formula:
Pi Example (2) start_time = MPI_Wtime(); MPI_Bcast(&n, 1, MPI_INT, host_rank, MPI_COMM_WORLD); end_time = MPI_Wtime(); communication_time = end_time - start_time;
Pi Example (3) start_time = MPI_Wtime(); h = 1.0 / (double) n; sum = 0.0; for (i = my_rank + 1; i <= n; i += pool_size) { x = h * ((double)i - 0.5); sum += f(x); } mypi = h * sum; end_time = MPI_Wtime(); computation_time = end_time - start_time;
Pi Example (4) start_time = MPI_Wtime(); MPI_Reduce(&mypi, &pi, 1, MPI_DOUBLE, MPI_SUM, host_rank, MPI_COMM_WORLD); end_time = MPI_Wtime(); communication_time = communication_time + end_time - start_time; http://dune.mcs.kent.edu/~farrell/dist/ref/mpitut/mpi.html