MPI:How 在有或没有 MPI_Barrier 的情况下正确测量实际时间?
MPI:How to measure actual time correctly with or without MPI_Barrier?
我测量广播时间的 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是一个集体通信(所有进程向根进程报告以继续程序)。所以我们测量的时间将是 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
但我不知道他们如何衡量 it.Even 我 运行 它在一台机器上,MPI_Broadcast 成本真的是 0% 吗???
从你的例子看来,你想知道的是"the time from the first process entering the Bcast call until the time of the last process leaving the Bcast call"。请注意,并非所有时间都花在 MPI_Bcast 内。事实上,完全有可能一些进程在其他进程进入之前就已经离开了 Bcast 调用。
无论如何,最好的方法可能是测量每个进程的第一个 Barrier 和 Bcast 退出之间的时间,并使用 Reduction 找到最大值:
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 推荐的性能分析工具,因为它们处理了所有的多进程通信特性。
我测量广播时间的 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是一个集体通信(所有进程向根进程报告以继续程序)。所以我们测量的时间将是 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
但我不知道他们如何衡量 it.Even 我 运行 它在一台机器上,MPI_Broadcast 成本真的是 0% 吗???
从你的例子看来,你想知道的是"the time from the first process entering the Bcast call until the time of the last process leaving the Bcast call"。请注意,并非所有时间都花在 MPI_Bcast 内。事实上,完全有可能一些进程在其他进程进入之前就已经离开了 Bcast 调用。
无论如何,最好的方法可能是测量每个进程的第一个 Barrier 和 Bcast 退出之间的时间,并使用 Reduction 找到最大值:
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 推荐的性能分析工具,因为它们处理了所有的多进程通信特性。