如何计算cilk_spawn的时间

How to calculate time for a cilk_spawn

本文关键字:spawn 时间 cilk 何计算 计算      更新时间:2023-10-16

感谢您查看帖子

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

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

#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"中放置一些计时器开始/停止语句,并忠实地计算生成时间。

感谢您的关注。