首先,我知道如何在串行Python脚本中记录经过的时间。
import time
time_start = time.time()
...
time_end = time.time()
print("The elapsed time is", time_end-time_start, "seconds")
但是,如果我通过mpi4py启用多进程,我不知道如何打印经过的时间。你能给我举个例子或说明一下吗?
我有点晚了,但是我已经弄清楚了如何在不产生混乱输出的情况下打印经过的时间。如
import time
time_start = time.time()
time.sleep(3)
time_end = time.time()
elapsedTime = time_end - time_start
print(f'The elapsed time is {elapsedTime} seconds')
The elapsed time is 3.000737428665161 seconds
为了避免这种草率的输出,可以这样做:
import time
time_start = time.time()
time_end = time.time()
elapsedTime = int(time_end - time_start)
print(f'The elapsed time is {elapsedTime} seconds')
The elapsed time is 3 seconds
我希望这对你有帮助!