c++ - 如何计算 cilk_spawn 的时间

标签 c++ c execution-time gprof cilk

感谢您查看帖子

我正在对一些 Cilk Plus 代码进行基准测试,并希望计算完成“生成”操作所需的时间。我感兴趣的只是计算生成所需的时间,而不是 fib() 所需的计算时间。这可以做到吗?

将计时器放入以下代码中会按预期工作吗?如果我的想法是正确的,将用timer_start()和timer_stop()替换“//RRS”,完成工作吗?

#include <stdio.h>
#include <stdlib.h>   
int fib(int n)
{
  if (n < 2) return n;
  else {
  // RRS: Start timer t1 here ??
  int x = cilk_spawn fib(n-1);
  // RRS: Stop timer t1 here ??

  int y = fib(n-2);

  // RRS: Start timer t2 here ??       
  cilk_sync;
  // RRS: Stop timer t2 here ??

  return x + y;
  }
}
 
int main(int argc, char *argv[])
{
  int n = atoi(argv[1]);
  int result = fib(n);
  printf("Fibonacci of %d is %d.\n", n, result);
  return 0;
}

最佳答案

回答我自己的问题:

我可以在注释行“//RRS”中放置一些计时器启动/停止语句,并忠实地计算生成时间。

感谢您的关注。

关于c++ - 如何计算 cilk_spawn 的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10063912/

相关文章:

c++ - xlib 防止关闭按钮退出应用程序

c - 没有定义函数参数类型默认为int?我疯了吗?

C++ 计数时间克服 clock_t 的 72 分钟范围

c++ - 数组错误

c++ - 我应该如何表示我拥有的连续元素序列?

c++ - 当函数返回时,函数中分配的内存是否被释放?

c++ - fstream 打开时不处理异常

c - 移植 Autodesk Animator Pro 以实现跨平台

sql - 简单的更改会导致 SQL 查询执行时间急剧增加

php - 在检索 MySQL 表时克服 PHP 内存耗尽或执行时间错误