MPI运行时间测量

翻译自:https://stackoverflow.com/questions/5298739/mpi-global-execution-time
使用MPI_BarrierMPI_Wtime函数,前者使得各进程对齐,后者记录了时间节点,以秒为单位(可以通过MPI_Wtick函数微调)。样本代码如下:

double start, end;

MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);

MPI_Barrier(MPI_COMM_WORLD); /* IMPORTANT */
start = MPI_Wtime();

/* ... do work ... */

MPI_Barrier(MPI_COMM_WORLD); /* IMPORTANT */
end = MPI_Wtime();

MPI_Finalize();

if (rank == 0) { /* use time on master node */
    printf("Runtime = %f\n", end-start);
}

猜你喜欢

转载自blog.csdn.net/silent56_th/article/details/80419314