在堆栈上分配数组时出现运行时错误

时间:2016-10-08 07:29:47

标签: c arrays stack runtime-error long-integer

import numpy
import theano
import theano.tensor as T 

def recurrence(pre_output, a):
    print("test")
    return pre_output*a

x = T.ivector('x')

o, updates = theano.scan(
    fn = recurrence,
    outputs_info = T.ones_like(x),
    non_sequences = x,
    n_steps = 5
)

fun = theano.function([x], o)
print(fun([1,2,3]))

当我运行这个时,我总是遇到运行时错误。任何人都可以建议我一个克服它的解决方案吗?我需要这个用于竞争性编程问题,其中ChessBoard可能有1000000000 * 1000000000个方格,我需要用它执行多个操作。

1 个答案:

答案 0 :(得分:4)

因为在大多数实现中,您无法创建大的局部变量。

你真的有10000000000 * 10000000000 = 100000000000000000字节的内存吗?

在大多数系统上,限制介于64k和10mibyte之间。当然不是你想要制作[] []的任何地方。

您需要使用malloc来尝试分配内存。局部变量在运行时在堆栈上生成,堆栈内存不足,导致程序崩溃。

相关问题