大矩阵计算 [英] large matrix computation

查看:140
本文介绍了大矩阵计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C ++编写一个简单的代码,我编译它与g ++在linux ubuntu 11.04和我没有得到任何错误,但是当我运行可执行文件,我得到这个错误分段错误。

I write a simple code in C++ and I compile it with g++ on linux ubuntu 11.04 and I don't get any errors but when I run the executable file, I get this error "segmentation fault".

我知道我的代码没有问题,并且这个错误与编译器有关。

I know that my code has no problem and tHat this error is related to the compiler.

有人可以帮助我吗?

我的代码是

#include <math.h>
int main()
{
    double a[200][200][200],b[200][200][200],c[200][200][200];
    int i,j,k;

    double const pi=3.14;

    for(k=0;k<200;k++)
    {
        for(j=0;j<200;j++)
        {
            for(i=0;i<200;i++)
            {
                a[i][j][k]=sin(1.5*pi*i)*cos(3.5*pi*j)*k;
                b[i][j][k]=cos(1.5*pi*i)*cos(2.5*pi*k)*j;
                c[i][j][k]=a[i][j][k]-b[i][j][k];
            }
        }
    }
}


推荐答案

此函数可以帮助您:

double ***alloc3d(int l, int m, int n) {
    double *data = new double [l*m*n];
    double ***array = new double **[l];
    for (int i=0; i<l; i++) {
        array[i] = new double *[m];
        for (int j=0; j<m; j++) {
            array[i][j] = &(data[(i*m+j)*n]);
        }
    }

    return array;
}

这篇关于大矩阵计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆