Segmentation Problem at 1024 size matrixes multiplication

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • queer
    New Member
    • Mar 2014
    • 2

    #1

    Segmentation Problem at 1024 size matrixes multiplication

    I am able to compute the matrix multiplication algorithm upto 512 input square matrices of random numbers. I get a segmentation error at 1024 size input square matrices.

    Code:
    for(i=1;i<=m;i++)
    {
    for(j=1;j<=q;j++)
    {
    C[i][j]=0;
    for(k=1;k<=p;k++)
    {
    //printf("i %d k %d j %d",i,k,j);
    //printf("Aik %d Bkj%d",A[i][k],B[k][j]);
    float d = A[i][k]*B[k][j];
    C[i][j] = C[i][j] +d; 
    // printf("%d ",C[i][j]); 
    }
    printf("\n");
    printf("%d ",C[i][j]);	
    C[i][j]=0;
    }
    }
    Last edited by Niheel; Apr 1 '14, 05:24 PM. Reason: Code added
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    You need to post more code. Missing is the size of the array and the values of various variables like m, q and p.

    Comment

    • queer
      New Member
      • Mar 2014
      • 2

      #3
      use dynamic memory allocation
      Last edited by queer; Mar 31 '14, 01:26 AM. Reason: please let me know if you require other details.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        You will get a segmentation error anytime you ry to access memory you have not allocated. It doesn't matter if you allocated it (dynamic) or the compiler allocated it (static).

        Comment

        • techboy
          New Member
          • Apr 2014
          • 28

          #5
          You must take care when you multiply two integers your result is not exceeding 32 bit integer.instead try using long long int (64-bit integer)

          Comment

          • evena
            New Member
            • Apr 2014
            • 1

            #6
            Your loops start at 1, C/C++ indexing starts at 0, so maybe you
            should: (start at 0, use < instead of <=)

            for(i = 0; i < m; i++)
            for(j = 0; j < q; j++)
            for(k = 0; k < p; k++)

            etc.

            Comment

            Working...