轉載自: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\n", end-start); }