Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 数组-错误:分配中的类型不兼容_C - Fatal编程技术网

C 数组-错误:分配中的类型不兼容

C 数组-错误:分配中的类型不兼容,c,C,我有一个问题,我想可能有一个简单的答案,但我还没有找到任何文件证实我的怀疑 我的程序是将两个方阵相乘,整个代码有点长,所以我只粘贴了下面的相关部分。在编译代码时,我不断收到一条“错误:赋值中的不兼容类型”消息。我试图分配子矩阵suba,subb,subc和a,b,c的相应部分。这是因为我使用变量v和w int行28-32吗?另外,为了确保我有正确的概念,如果我将矩阵的左上角指定给“子矩阵”,那么我只是指定一个指针(例如subb)从大矩阵的指定位置开始,对吗 提前感谢您的帮助!非常感谢 struc

我有一个问题,我想可能有一个简单的答案,但我还没有找到任何文件证实我的怀疑

我的程序是将两个方阵相乘,整个代码有点长,所以我只粘贴了下面的相关部分。在编译代码时,我不断收到一条“错误:赋值中的不兼容类型”消息。我试图分配子矩阵suba,subb,subc和a,b,c的相应部分。这是因为我使用变量v和w int行28-32吗?另外,为了确保我有正确的概念,如果我将矩阵的左上角指定给“子矩阵”,那么我只是指定一个指针(例如subb)从大矩阵的指定位置开始,对吗

提前感谢您的帮助!非常感谢

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;
}
struct线程
{
pthread\u t id;//要在函数中使用的线程id
int n;//块的大小
浮点**suba;//子矩阵a
浮点**subb;//子矩阵b
浮点**subc;//子矩阵c
};
int main(int argc,char*argv[])
{
int n;//矩阵的维数
int p;//程序中的线程数
浮点*sa、*sb、*sc;//矩阵A、B和C的存储
浮点**a、**b、**c;//访问矩阵a、b和c的二维数组
int i,j;
结构线程*t;
t=(结构线程*)malloc(p*sizeof(结构线程));
int x=-1;
intz;
对于(z=0;z
t[z]。suba
属于
float**

a[w][v]
属于
float
类型

你是说

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

阅读第6节。我没有注意到那个部分,那是我的错误。我试图使
t[z].suba
的左上角等于
a[w][v]
。但我刚刚意识到,为了实现这一点,并且不出现分段错误,我需要初始化
suba,subb,subc的两个维度,谢谢你的帮助!回到绘图板上。