简体   繁体   English

MPI总运行时间

[英]MPI Total run time

I have one program (which calculates the matrix multiplication with cannon algorithm), is implemented in MPI for C, I have set a clock to see the TOTAL time of this program, with total I mean all the process sum. 我有一个程序(用cannon算法计算矩阵乘法),在MPI中实现C,我设置了一个时钟来查看这个程序的TOTAL时间,总计是指所有的过程总和。

But as a result I get the time of each process. 但结果我得到了每个过程的时间。

Part of my code at the beginning of my main: 我的主要部分开头的部分代码:

 clock_t begin, end;
 double time_spent;
 begin = clock();

 /* Initializing */
 MPI_Init (&argc, &argv);

Then at the end of my code I have: 然后在我的代码结束时,我有:

  MPI_Finalize();

  end = clock();
  time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
  printf("\n\nTIME: %f SECONDS\n\n", time_spent);

Assuming what you want is the sum of the individual times for each of your processes, you will need to: 假设您想要的是每个流程的各个时间的总和,您需要:

  1. Move your measure of the end of time before the call to MPI_Finalize() , as you'll need an extra communication; 在调用MPI_Finalize()之前移动您的时间结束度量,因为您需要额外的通信;
  2. Collect the individual times via an MPI_Reduce() to process #0 (for example); 通过MPI_Reduce()收集各个时间来处理#0(例如); and finally 最后
  3. Print this time with process 0. 使用流程0打印此时间。

Aside from this, unless you have a compelling reason for doing otherwise, I would encourage you to use MPI_Wtime() as timer rather than the somewhat misleading clock() timer. 除此之外,除非你有其他令人信服的理由,否则我鼓励你使用MPI_Wtime()作为计时器而不是有些误导性的clock()计时器。

The code could then look as follow: 然后代码可能如下所示:

int main( int *argc, char* argv[] ) {
    MPI_Init( &argc, &argv );
    double tbeg = MPI_Wtime();

    // a lot of stuff here

    // you might want a barrier here...
    // MPI_Barrier( MPI_COMM_WORLD );
    double elapsedTime = MPI_Wtime() - tbeg;
    double totalTime;
    MPI_Reduce( &elapsedTime, &totalTime, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD );
    if ( rank == 0 ) {
        printf( "Total time spent in seconds id %f\n", totalTime );
    }
    MPI_Finalize();
    return 0;
}

Yes of course what you get is correct. 是的,当然你得到的是正确的。

If you want the TOTAL TIME, ie the sum of the time spent in every process, then send the local time_spent of every node in the master node, perform the summation of the local time_spent 's there and print it. 如果你想要TOTAL TIME,即每个进程花费的时间总和,那么发送主节点中每个节点的本地time_spent ,在那里执行本地time_spent的求和并打印它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM