我試圖給我的小程序,它使用MPI,我希望輸出在文件中的時間。帶有標誌運行應用程序的旗幟的時間命令
Im試試命令:time --output=rt.txt mpirun -np 2 a.out
。但time
和mpirun
的標誌似乎衝突。
任何想法如何工作?
我試圖給我的小程序,它使用MPI,我希望輸出在文件中的時間。帶有標誌運行應用程序的旗幟的時間命令
Im試試命令:time --output=rt.txt mpirun -np 2 a.out
。但time
和mpirun
的標誌似乎衝突。
任何想法如何工作?
您確定嗎?從手冊頁二進制time
選項時必須出現之前命令在命令行上。 任何命令後,在命令行上作爲參數傳遞給 COMMAND
time
您正在使用哪個
?請注意,有一個內置shell time
和一個單獨的二進制文件。我懷疑你需要使用單獨的二進制文件而不是內置的。只需指定它爲/usr/bin/time
(或安裝在任何地方)
而不是使用時間二進制,您是否聽說過MPI_Wtime
函數?使用MPI_Wtime
定時應用程序可以產生更準確的整個並行作業執行時間結果。您可以使用MPI_Wtime
如下:
#include <stdio.h>
#include <mpi.h>
int main(void) {
MPI_Init(NULL, NULL);
MPI_Barrier(MPI_COMM_WORLD);
// Get the program start time after all processes have initialized and synchronized
double start_time = MPI_Wtime();
// Do parallel processing here...
sleep(1);
// Synchronize all the processes again and find out the total execution time
MPI_Barrier(MPI_COMM_WORLD);
double execution_time = MPI_Wtime() - start_time;
// Print the execution time from the root process
int world_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
if (world_rank == 0) {
printf("Execution time %lf\n", execution_time);
}
MPI_Finalize();
return 0;
}
這個程序應打印一些接近這一點 - 從在Ubuntu在bash> 執行時間1.0
哇,謝謝!我的確瞭解MPI_Wtime,但對於上面的任務,我只需要粗略比較不同的執行方式進程數(-np x)。所以,確切的時機並不是真的需要。但是非常感謝代碼。一定會使用它! – TeaOverflow
林USIG內置'time'。 – TeaOverflow
我懷疑那是你的問題 –
這個在manpage中的聲明導致我認爲語法應該是這樣的 – TeaOverflow