gpt4 book ai didi

c - 高值段错误 (Xeon Phi)

转载 作者:行者123 更新时间:2023-11-30 17:23:26 29 4
gpt4 key购买 nike

我正在通过 Stampede 使用 Xeon Phi 解决 Collat​​z 猜想问题。我已经测试过我的代码,对于高达 100,000 的值可以正常工作,但是测试高达 100 万的值时,我几乎立即收到段错误(“SIGSEV”)。我已经把头撞在墙上好几天了,但就是无法找出这个错误。非常感谢任何帮助。

typedef unsigned long long bigInt;

// Number to test to (starting from 1)
#define bigSize 100000

typedef struct {
int numSteps;
bigInt stopPoint;
} batcher;

typedef struct {
bigInt num;
batcher to_batch;
} to_ret;
int main () {
//Stores values as [num][#steps to smaller val][smaller val]
to_ret retlist[bigSize];
//Stores values as [#steps to smaller val][smaller val], sorted by num
batcher results[bigSize];
...

#pragma offload target(mic:0) inout(retlist) shared(retlist)
{
#pragma omp parallel for
for(i = 1; i < bigSize; i++){
retlist[i].num = i + 1;
bigInt next = retlist[i].num;
int count = 0;

do {
count++;

if (next%2 == 1)
next=(3*next+1)/2;
else
next/=2;

} while(next > retlist[i].num);

retlist[i].to_batch.numSteps = count;
retlist[i].to_batch.stopPoint = next;
}
}

///Organizes data into a sorted array
#pragma omp parallel for
for (i = 0; i < bigSize; i++){
results[retlist[i].num - 1] = retlist[i].to_batch;
}
...
}

我非常有信心问题出在上面代码段的某个地方。

最佳答案

以下代码可以正确编译:

  • 不会溢出堆栈
  • 不会用一堆结构的 typedef 来混淆代码
  • 不隐藏 bigNum 是一个 unsigned long long int。

  • 确实包含索引变量“i”的声明

我无法访问优化编译指示,因此暂时将它们注释掉。

//typedef unsigned long long bigInt;

// Number to test to (starting from 1)
#define bigSize (100000)

struct batcher
{
int numSteps;
//bigInt stopPoint;
unsigned long long stopPoint;
};

struct to_ret
{
//bigInt num;
unsigned long long num;
struct batcher to_batch;
};

//Stores values as [num][#steps to smaller val][smaller val]
static struct to_ret retlist[bigSize];
//Stores values as [#steps to smaller val][smaller val], sorted by num
static struct batcher results[bigSize];

int main ()
{
int i;
// more code here

////#pragma offload target(mic:0) inout(retlist) shared(retlist)
{
////#pragma omp parallel for
for(i = 1; i < bigSize; i++)
{
retlist[i].num = i + 1;
//bigInt next = retlist[i].num;
unsigned long long next = retlist[i].num;
int count = 0;

do
{
count++;

if (next%2 == 1)
next=(3*next+1)/2;
else
next/=2;

} while(next > retlist[i].num);

retlist[i].to_batch.numSteps = count;
retlist[i].to_batch.stopPoint = next;
}
}

///Organizes data into a sorted array
////#pragma omp parallel for
for (i = 0; i < bigSize; i++){
results[retlist[i].num - 1] = retlist[i].to_batch;
}
// more code here

return(0);
} // end function: main

关于c - 高值段错误 (Xeon Phi),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27584467/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com