Skip to content

Instantly share code, notes, and snippets.

@congqiao
Created September 16, 2014 01:56
Show Gist options
  • Save congqiao/ad2eabcb299f1c9809e4 to your computer and use it in GitHub Desktop.
Save congqiao/ad2eabcb299f1c9809e4 to your computer and use it in GitHub Desktop.
Timing MPI routines
#include <mpi.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
int num = 7;
int i;
int rank;
double begin, end;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Barrier(MPI_COMM_WORLD);
begin = MPI_Wtime();
for (i = 0; i != 1000000; ++i) {
MPI_Bcast(&num, 1, MPI_INT, 0, MPI_COMM_WORLD);
}
MPI_Barrier(MPI_COMM_WORLD);
end = MPI_Wtime();
MPI_Finalize();
if (rank == 0) {
printf("Run time: %f\n", end-begin);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment