内存不足错误。分配...

发布于 2024-08-20 00:27:08 字数 788 浏览 3 评论 0原文

我正在尝试使用 gprof 命令:gprof -sexecutable.exe gmon.out gmon.sum 来合并从两次运行程序中收集的分析数据。但出现以下错误:

gprof:在总共 196608 字节之后分配 3403207348 字节时内存不足

我的程序非常简单(只有一个 for 循环)。如果我运行一次,运行时间太短(显示 0.00 秒),gprof 无法记录。

在 CygWin 中,我执行以下步骤:

  1. gcc -pg -o fl forAndWhilLoop.c

  2. fl(运行程序)

  3. mv gmon.out gmon.sum

  4. fl(运行程序)

  5. gprof -s fl .exe gmon.out gmon.sum

  6. gprof fl.exe gmon.sum>gmon.out

  7. gprof fl.exe

我的程序:

int main(void)
{
    int fac=1;
    int count=10;
    int k;

    for(k=1;k<=count;k++)
    {
        fac = fac * k;
    }

    return 0;
}

那么有人可以帮我解决这个问题吗?谢谢!

I'm trying to use a gprof command: gprof -s executable.exe gmon.out gmon.sum to merge profiling data gathered from 2 runs of my programs. But the following error appears:

gprof: out of memory allocating 3403207348 bytes after a total of 196608 bytes

My program is quite simple (just one for loop). If i run it once, the run time is too short (it shows 0.00s) for gprof to record.

In CygWin, I do the following steps:

  1. gcc -pg -o fl forAndWhilLoop.c

  2. fl (run the program)

  3. mv gmon.out gmon.sum

  4. fl (run the program)

  5. gprof -s fl.exe gmon.out gmon.sum

  6. gprof fl.exe gmon.sum>gmon.out

  7. gprof fl.exe

My program:

int main(void)
{
    int fac=1;
    int count=10;
    int k;

    for(k=1;k<=count;k++)
    {
        fac = fac * k;
    }

    return 0;
}

So can anyone help me with this problem? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

川水往事 2024-08-27 00:27:08

如果您只想计时,在我的机器上它是105ns。这是代码:

void forloop(void){ 
    int fac=1; 
    int count=10; 
    int k; 

    for(k=1;k<=count;k++) 
    { 
        fac = fac * k; 
    } 
} 

int main(int argc, char* argv[])
{
    int i;
    for (i = 0; i < 1000000000; i++){
        forloop();
    }
    return 0;
}

明白了吗?我使用了手持秒表。由于它运行 10^9 次,因此秒 = 纳秒。

像这样展开内循环将时间减少到92ns

int k = 1;
while(k+5 <= count){
    fac *= k * (k+1) * (k+2) * (k+3) * (k+4);
    k += 5;
}
while(k <= count){
    fac *= k++;
}

从调试切换到发布版本将其降低到21ns。您只能期望在实际热点中实现这种加速,这就是。

If all you want is to time it, on my machine it's 105ns. Here's the code:

void forloop(void){ 
    int fac=1; 
    int count=10; 
    int k; 

    for(k=1;k<=count;k++) 
    { 
        fac = fac * k; 
    } 
} 

int main(int argc, char* argv[])
{
    int i;
    for (i = 0; i < 1000000000; i++){
        forloop();
    }
    return 0;
}

Get the idea? I used a hand-held stopwatch. Since it runs 10^9 times, seconds = nanoseconds.

Unrolling the inner loop like this reduced the time to 92ns;

int k = 1;
while(k+5 <= count){
    fac *= k * (k+1) * (k+2) * (k+3) * (k+4);
    k += 5;
}
while(k <= count){
    fac *= k++;
}

Switching to Release build from Debug brought it down to 21ns. You can only expect that kind of speedup in an actual hotspot, which this is.

一紙繁鸢 2024-08-27 00:27:08

看来应该执行 pprof 而不是 gprof

It seems that pprof instead of gprof should be executed

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文