2012-11-28 23 views

回答

1

您確定嗎?從手冊頁二進制time

選項時必須出現之前命令在命令行上。 任何命令後,在命令行上作爲參數傳遞給 COMMAND

time您正在使用哪個

?請注意,有一個內置shell time和一個單獨的二進制文件。我懷疑你需要使用單獨的二進制文件而不是內置的。只需指定它爲/usr/bin/time(或安裝在任何地方)

+0

林USIG內置'time'。 – TeaOverflow

+0

我懷疑那是你的問題 –

+0

這個在manpage中的聲明導致我認爲語法應該是這樣的 – TeaOverflow

1

而不是使用時間二進制,您是否聽說過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

+0

哇,謝謝!我的確瞭解MPI_Wtime,但對於上面的任務,我只需要粗略比較不同的執行方式進程數(-np x)。所以,確切的時機並不是真的需要。但是非常感謝代碼。一定會使用它! – TeaOverflow