簡體   English   中英

數組-錯誤:分配中的類型不兼容

[英]Arrays - error: incompatible types in assignment

我有一個問題,我想可能會有一個簡單的答案,但是我在任何地方都找不到任何文檔來證實我的懷疑。

我的程序是將兩個平方矩陣相乘,整個代碼有點長,所以我只粘貼了下面的相關部分。 編譯代碼時,我不斷收到“錯誤:分配中的類型不兼容”消息。 我正在嘗試為子矩陣suba,subb,subc分配a,b和c的相應部分。 這是因為我正在使用變量v和w int第28-32行嗎? 另外,只是為了確保我有正確的概念,如果我將矩陣的左上角分配給“ submatrix”,那么我只是分配了一個指針(例如subb),以從big的指定位置開始矩陣,對不對?

先謝謝您的幫助! 被IMMENSELY認可

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

t[z].suba的類型為float **

a[w][v]的類型為float

你的意思是

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM