时间命令与标志运行应用程序与标志

时间:2012-11-28 10:52:30

标签: shell unix command-line time mpi

我试图计算我的小程序,它使用MPI,我想要输出文件。

我正在尝试的命令:time --output=rt.txt mpirun -np 2 a.out。但是timempirun的标记似乎发生冲突。

任何想法如何起作用?

2 个答案:

答案 0 :(得分:1)

你确定吗?来自二进制文件的手册页 time

  

时间选项必须出现在COMMAND之前的命令行中。   COMMAND之后命令行上的任何内容都作为参数传递给   COMMAND

您使用的是哪个time?请注意,有一个内置shell time和一个单独的二进制文件。我怀疑你需要使用单独的二进制文件而不是内置的二进制文件。只需将其指定为/usr/bin/time(或安装在何处)

答案 1 :(得分: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;
}

此程序应打印出关闭此内容的信息 - &gt; 执行时间1.0