MPI:如何在有或没有MPI_Barrier的情况下正确测量实际时间?

时间:2016-03-17 13:12:20

标签: mpi time-complexity complexity-theory openmpi hpc

用于衡量广播时间的我的MPI计划:

MPI_Barrier(MPI_COMM_WORLD); 
total_mpi_bcast_time -= MPI_Wtime(); 
MPI_Bcast(data, num_elements, MPI_INT, 0, MPI_COMM_WORLD); 
MPI_Barrier(MPI_COMM_WORLD); 
total_mpi_bcast_time += MPI_Wtime(); 

我们需要MPI_Barrier等到所有进程完成其作业(同步)。但实际上,MPI_Barrier是一个集体通信(所有进程都报告给root进程继续程序)。所以我们测量的时间将是Barrier_time + Broadcast_time 。 那么如何正确测量广播时间呢? 这是Scalasca的结果

Estimated aggregate size of event trace:                   1165 bytes
Estimated requirements for largest trace buffer (max_buf): 292 bytes
Estimated memory requirements (SCOREP_TOTAL_MEMORY):       4097kB
(hint: When tracing set SCOREP_TOTAL_MEMORY=4097kB to avoid intermediate flushes
or reduce requirements using USR regions filters.)

flt     type max_buf[B] visits time[s] time[%] time/visit[us]  region
        ALL     291       32   0.38    100.0       11930.30  ALL
        MPI     267       28   0.38    100.0       13630.27  MPI
        COM     24        4    0.00     0.0          30.54  COM

        MPI     114       8    0.00     0.1          33.08  MPI_Barrier
        MPI     57        4    0.00     0.0          26.53  MPI_Bcast
        MPI     24        4    0.00     0.2         148.50  MPI_Finalize
        MPI     24        4    0.00     0.0           0.57  MPI_Comm_size
        MPI     24        4    0.00     0.0           1.61  MPI_Comm_rank
        MPI     24        4    0.38    99.7       95168.50  MPI_Init
        COM     24        4    0.00     0.0          30.54  main

但我不知道他们是如何衡量它的。即使我在一台机器上运行它,MPI_Broadcast的成本真的是0%???

1 个答案:

答案 0 :(得分:0)

从你的例子看,你想知道的是“从第一个进程进入Bcast通话到最后一个进程离开Bcast通话的时间”。请注意,并非所有时间实际上都花在了MPI_Bcast中。实际上,完全有可能某些进程在其他人进入之前就离开了Bcast呼叫。

无论如何,最好的方法是测量每个过程中第一个屏障和Bcast出口之间的时间,并使用减少来找到最大值:

MPI_Barrier(MPI_COMM_WORLD);
local_mpi_bcast_time -= MPI_Wtime();

MPI_Bcast(data, num_elements, MPI_INT, 0, MPI_COMM_WORLD); 
local_mpi_bcast_time += MPI_Wtime();

MPI_Reduce(&local_mpi_bcast_time, &total_mpi_bcast_time, 1, MPI_DOUBLE,            
           MPI_MAX, 0, MPI_COMM_WORLD);

这仍然不是100%准确,因为流程可能会在稍微不同的时间留下障碍,但是你可以通过MPI获得最佳效果。

我还建议您看一下Zulan建议的性能分析工具,因为它们可以处理所有多过程通信的特性。

相关问题