1. <small id='nBV30'></small><noframes id='nBV30'>

      <tfoot id='nBV30'></tfoot>
    2. <i id='nBV30'><tr id='nBV30'><dt id='nBV30'><q id='nBV30'><span id='nBV30'><b id='nBV30'><form id='nBV30'><ins id='nBV30'></ins><ul id='nBV30'></ul><sub id='nBV30'></sub></form><legend id='nBV30'></legend><bdo id='nBV30'><pre id='nBV30'><center id='nBV30'></center></pre></bdo></b><th id='nBV30'></th></span></q></dt></tr></i><div id='nBV30'><tfoot id='nBV30'></tfoot><dl id='nBV30'><fieldset id='nBV30'></fieldset></dl></div>
    3. <legend id='nBV30'><style id='nBV30'><dir id='nBV30'><q id='nBV30'></q></dir></style></legend>
      • <bdo id='nBV30'></bdo><ul id='nBV30'></ul>

      C++:Linux 中的时序(使用 clock())不同步(由于 OpenMP?)

      C++: Timing in Linux (using clock()) is out of sync (due to OpenMP?)(C++:Linux 中的时序(使用 clock())不同步(由于 OpenMP?))
        <tbody id='3SeMC'></tbody>

        1. <tfoot id='3SeMC'></tfoot>
        2. <i id='3SeMC'><tr id='3SeMC'><dt id='3SeMC'><q id='3SeMC'><span id='3SeMC'><b id='3SeMC'><form id='3SeMC'><ins id='3SeMC'></ins><ul id='3SeMC'></ul><sub id='3SeMC'></sub></form><legend id='3SeMC'></legend><bdo id='3SeMC'><pre id='3SeMC'><center id='3SeMC'></center></pre></bdo></b><th id='3SeMC'></th></span></q></dt></tr></i><div id='3SeMC'><tfoot id='3SeMC'></tfoot><dl id='3SeMC'><fieldset id='3SeMC'></fieldset></dl></div>

            1. <legend id='3SeMC'><style id='3SeMC'><dir id='3SeMC'><q id='3SeMC'></q></dir></style></legend>
                <bdo id='3SeMC'></bdo><ul id='3SeMC'></ul>

                <small id='3SeMC'></small><noframes id='3SeMC'>

                本文介绍了C++:Linux 中的时序(使用 clock())不同步(由于 OpenMP?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                在程序的顶部和结尾,我使用 clock() 来计算我的程序需要多长时间才能完成.不幸的是,它似乎只需要报告的一半时间.我用时间"命令仔细检查了这一点.

                At the top and end of my program I use clock() to figure out how long my program takes to finish. Unfortunately, it appears to take half as long as it's reporting. I double checked this with the "time" command.

                我的程序报告:45.86s 内完成

                My program reports: Completed in 45.86s

                时间命令报告:真正的 0m22.837s用户 0m45.735s系统0m0.152s

                Time command reports: real 0m22.837s user 0m45.735s sys 0m0.152s

                用我的手机计时,它在 23 秒内完成(又名:真实"时间).用户"时间是所有线程的总和,这很有意义,因为我使用的是 OpenMP.(你可以在这里阅读:'real'、'user' 和 'sys' 在 time(1) 的输出中是什么意思?)

                Using my cellphone to time it, it completed in 23s (aka: the "real" time). "User" time is the sum of all threads, which would make sense since I'm using OpenMP. (You can read about it here: What do 'real', 'user' and 'sys' mean in the output of time(1)?)

                那么,为什么 clock() 在用户"时间而不是实时"时间报告?是否应该使用不同的函数来计算我的程序运行了多长时间?

                So, why is clock() reporting in "user" time rather than "real" time? Is there a different function I should be using to calculate how long my program has been running?

                作为旁注,Windows 的时钟()按预期工作并实时"报告.

                As a side note, Windows' clock() works as expected and reports in "real" time.

                推荐答案

                用户 0m45.735s

                user 0m45.735s

                clock() 根据 7.27.2.1 测量进程使用的 CPU 时间(尽其所能)

                clock() measures CPU time the process used (as good as it can) per 7.27.2.1

                clock 函数返回实现对程序使用的处理器时间的最佳近似值,自一个实现定义的时代开始,仅与程序调用相关.

                The clock function returns the implementation’s best approximation to the processor time used by the program since the beginning of an implementation-defined era related only to the program invocation.

                而不是挂钟时间.因此 clock() 报告的时间接近 time 报告的 user 时间是正常且符合标准的.

                and not wall clock time. Thus clock() reporting a time close to the user time that time reports is normal and standard-conforming.

                为了测量经过的时间,如果你可以假设 POSIX,使用 clock_gettime 可能是最好的选择,标准函数 time() 也可以用于那个,但是不是很细粒度.

                To measure elapsed time, if you can assume POSIX, using clock_gettime is probably the best option, the standard function time() can also be used for that, but is not very fine-grained.

                这篇关于C++:Linux 中的时序(使用 clock())不同步(由于 OpenMP?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How to print vector#39;s data(如何打印矢量的数据)
                Visual C++ appends 0xCC (int3) bytes at the end of functions(Visual C++ 在函数末尾附加 0xCC (int3) 字节)
                How to use a variable inside a _T wrapper?(如何在 _T 包装器中使用变量?)
                MSVC++ warning flags(MSVC++ 警告标志)
                How to read file which contains uxxxx in vc++(如何在vc++中读取包含uxxxx的文件)
                stack overflow error in C++ program(C++程序中的堆栈溢出错误)

                <small id='7rjE0'></small><noframes id='7rjE0'>

                  <tbody id='7rjE0'></tbody>

                  <legend id='7rjE0'><style id='7rjE0'><dir id='7rjE0'><q id='7rjE0'></q></dir></style></legend>
                  <tfoot id='7rjE0'></tfoot>
                      <bdo id='7rjE0'></bdo><ul id='7rjE0'></ul>
                        1. <i id='7rjE0'><tr id='7rjE0'><dt id='7rjE0'><q id='7rjE0'><span id='7rjE0'><b id='7rjE0'><form id='7rjE0'><ins id='7rjE0'></ins><ul id='7rjE0'></ul><sub id='7rjE0'></sub></form><legend id='7rjE0'></legend><bdo id='7rjE0'><pre id='7rjE0'><center id='7rjE0'></center></pre></bdo></b><th id='7rjE0'></th></span></q></dt></tr></i><div id='7rjE0'><tfoot id='7rjE0'></tfoot><dl id='7rjE0'><fieldset id='7rjE0'></fieldset></dl></div>