我下载了Intel Parallel Studio,然后转到命令并输入:
source /opt/intel/bin/compilervars.sh intel64后跟:icpc file.cpp来运行Cilk plus文件。
file.cpp是cilkplus.org中使用的原始示例的简化版本,因此它应该可以工作,但它会产生分段错误
下面是我尝试使用cilk plus编译器运行的文件:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int fib(int n)
{
if (n < 2)
return n;
int x = cilk_spawn fib(n-1);
int y = fib(n-2);
cilk_sync;
return x + y;
}
int main(int argc, char *argv[])
{
int n = 39;
clock_t start = clock();
int result = fib(n);
clock_t end = clock();
double duration = (double)(end - start) / CLOCKS_PER_SEC;
printf("Calculated in %.3f seconds using %d workers.\n", duration, __cilkrts_get_nworkers());
return 0;
}发布于 2018-04-18 00:59:36
我认为问题出在39。
代码在我看来是正确的。虽然我从来没有使用过cilk,但从我得到的代码来看,考虑到你确实复制了它,代码似乎是正确的。
我猜39这个数字太大了。尝试更小或更大的数字。
如果有效,删除所有持续时间的废话,并为前40个案例尝试fib(i)的循环。在你把它搞乱之前,使用更简单的版本。
https://stackoverflow.com/questions/49883180
复制相似问题