mpi行列式,CODE:11分段错误

时间:2013-01-25 17:56:27

标签: c++ mpi

我是mpi的新手,我想用C ++编写一个程序来计算矩阵的行列式,并且在尝试编写它时,我在尝试使用mpi编译器编译时遇到此错误。

#include "mpi.h"
#include <iostream>
#include <stdio.h>
#include "/usr/include/malloc.h"

using namespace std;




int matrix[3][3] =  {{1,2,3},
                     {4,5,6},
                     {7,8,9}};

//**************


int** MakeMatrix (int** oldMatrix,int I,int J,int m,int n)
{
 int** newMatrix = (int**)malloc(sizeof(int*)*J);
 for(int i=0;i<J;i++)
 {
  newMatrix[i] = (int*)malloc(sizeof(int)*I);
 }
 for(int i=0;i<I-1;i++)
  for(int j=0;j<J-1;j++)
   if(i>=m)
    if(j>=n)
    {
     newMatrix[i][j]=oldMatrix[i+1][j+1];
    }
    else
    {
     newMatrix[i][j]=oldMatrix[i+1][j];
    }
   else
   {
    newMatrix[i][j]=oldMatrix[i][j];
   }
 return newMatrix;
}

 ///////////////////////

int determinan (int** lmatrix,int I,int J)
{
 if(I*J==1)
 {
  return lmatrix[I-1][J-1];
 }

 int minus = -1;
 int sum = 0;
 for(int j=0;j<J-1;j++)
 {
  for(int k=1;k<I+j+1;k++,minus*=minus);
  sum += minus*lmatrix[0][j]*determinan(MakeMatrix(lmatrix,I,J,0,j),I-1,J-1);
 }

 return sum;
}

///*************


int main(int argc,char **argv)
{
 //MPI_Init(&argc,&argv);
 cout<<determinan((int**)matrix,3,3)<<'\n';
 //MPI_Finalize();
 return 0;
}

以下是错误消息:

===================================================================================
=   BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
=   EXIT CODE: 11
=   CLEANING UP REMAINING PROCESSES
=   YOU CAN IGNORE THE BELOW CLEANUP MESSAGES
===================================================================================
YOUR APPLICATION TERMINATED WITH THE EXIT STRING: Segmentation fault (signal 11)
This typically refers to a problem with your application.
Please see the FAQ page for debugging suggestions

1 个答案:

答案 0 :(得分:0)

我确信存在多个问题。直接的是类型:

cout<<determinan((int**)matrix,3,3)<<'\n';
                 ^^^^^^^

这不是有效的演员,因为matrix不是指针数组。