1 / 11

Timing in MPI

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)

fontaine
Download Presentation

Timing in MPI

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Timing in MPI Tarik Booker MPI Presentation May 7, 2003

  2. What we will cover… • How to time programs • Sample Programs • My Samples • MPI Pi Program

  3. How to Time Programs • Very Easy • Simply use function MPI_Wtime()

  4. MPI_Wtime() • Null input • Returns a Long Float (double) • Not like UNIX “clock” function • MPI_Wtime() is somewhat arbitrary • Starts depending on node

  5. How to Time Code • Must use time blocks • Start time • End time • Time for your code is simply end_time – start_time.

  6. 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(); }

  7. 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(); }

  8. Pi Example • Uses MPI to compute value of Pi using formula:

  9. 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;

  10. 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;

  11. 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

More Related