wmarquez
wmarquez

Reputation: 147

Arrays - error: incompatible types in assignment

I have a question that I think might have a simple answer but I haven't found any documentation anywhere to confirm my suspicions.

My program is to multiply two square matrices, the entire code is a little long so I just pasted the relevant portions below. I keep getting an "error: incompatible types in assignment" message when I compile my code. I'm trying to assign sub matrices suba, subb, subc with the corresponding portions of a, b, and c. Is this because I'm using variables v and w int lines 28 - 32? Also, just to make sure that I have the right concept, if I assign the top left corner of a matrix to a "submatrix" then I'm just assigning a pointer (such as subb) to start at the specified position of the big matrix, right?

Thanks in advance for the help! It is IMMENSELY appreiciated

struct threads
{
  pthread_t id; //The thread id to use in functions
  int n; //size of block
  float **suba; //Sub-matrix a
  float **subb; //Sub-matrix b
  float **subc; //Sub-matrix c
};

int main( int argc, char* argv[ ] )
{
  int n; // dimension of the matrix
  int p; // number of threads in the program
  float *sa, *sb, *sc; // storage for matrix A, B, and C
  float **a, **b, **c; // 2-d array to access matrix A, B, and C
  int i, j;
  struct threads* t;

  t = ( struct threads* ) malloc( p * sizeof( struct threads ) );

  int x = -1;
  int z;
  for( z = 0; z < p; z++ )
  {
    t[ z ].n = n / sqrt( p );
    if( fmod( z, sqrt( p ) ) == 0 )
      x++;
    int w = ( int )( x * n / sqrt( p ) );
    int v = ( int )( fmod( z, sqrt( p ) ) * n / sqrt( p ) );
    t[z].suba = a[ w ][ v ];
    t[z].subb = b[ w ][ v ];
    t[z].subc = c[ w ][ v ];

    //pthread_create( &t[ z ].id, 0, threadWork, &t[ z ] );
  }

  return 0;
}

Upvotes: 2

Views: 1330

Answers (1)

dzada
dzada

Reputation: 5874

t[z].suba is of type float **

a[w][v] is of type float.

do you mean

t[z].suba[w][v] = a[w][v]; ?

Upvotes: 1

Related Questions