转载自:https://blog.csdn.net/silent56_th/article/details/80419314
翻译自:https://stackoverflow.com/questions/5298739/mpi-global-execution-time
使用MPI_Barrier
与MPI_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 ", end-start); }