Hello! I have a question that I think might be simple to answer but I haven't found any documentation anywhere to confirm my suspicions. I pasted only the relevant portions of my code below to the question that I'm asking. My program is supposed to multiply two square matrices.

The question that I have is about an "error: incompatible types in assignment" that I get when I try to assign suba, subb, subc with the corresponding portions of a, b, and c. Is this because I'm using variables v and w? 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 that start at the specified position of the big matrix, right?

Thanks in advance for the help! It is IMMENSELY appreiciated

``````struct threads
{
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;

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 ];

}

return 0;
}
``````

Let's use `t[z].suba = a[ w ][ v ];` as the example. Both suba and a have the same type (`float**`), so why are you subscripting a when trying to assign directly to suba? I suspect you're trying to copy the whole matrix:

``````t[z].suba = a;
``````

This of course has other problems because all of the `suba`'s in `t` will refer to the same matrix due to pointer aliasing, but fixing that involves allocating memory and changing how you copy the matrix from a direct pointer assignment to an element by element copy.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.