2
我试图将这些矩阵传递给使用结构的pthread。如何通过C中的结构传递矩阵的地址?
矩阵分配
double **A = (double **)malloc(size_matrix * sizeof(double*));
double **B = (double **)malloc(size_matrix * sizeof(double*));
double **C = (double **)malloc(size_matrix * sizeof(double*));
for(i = 0; i < size_matrix; i++){
A[i] = (double *)malloc(size_matrix * sizeof(double));
B[i] = (double *)malloc(size_matrix * sizeof(double));
C[i] = (double *)malloc(size_matrix * sizeof(double));
}
传递结构
for (t=0; t<thread_num-1; t++) {
thread_data[t].start = thread_count;
thread_data[t].end = thread_count + rows_per_thread-1;
thread_data[t].A_Matrix = *A;
thread_data[t].B_Matrix = *B;
thread_data[t].C_Matrix = *C;
thread_count += rows_per_thread;
}
结构
typedef struct {
int start;
int end;
double *A_Matrix;
double *B_Matrix;
double *C_Matrix;
} thread_data_t;
由线程执行的程序。
void *thread_mul(void *arg)
{
thread_data_t *td = (thread_data_t *) arg;
int i,j,k;
for (i=td->start; i<=td->end; i++) {
for (j=0; j<size_matrix; j++){
for(k=0;k<size_matrix;k++){
td->*C[i][j]+=td->*A[i][k]*td->(*B[k][j]);
}
}
}
pthread_exit(0);
}
问题是,当常规试图在
td->*C[i][j]+=td->*A[i][k]*td->(*B[k][j]);
执行它没有找到矩阵我得到一个错误说,它预计介于两者之间 - >和*。
感谢您的帮助!
谢谢,我认为这将对我有用! – djst2d 2014-09-20 14:03:33
@ djst2d欢迎您!试试看看它是否有效。如果确实如此,请考虑通过点击旁边的灰色复选标记来接受答案。这会为您在堆栈溢出中赢得新徽章,并让其他人知道您的问题已解决。 – dasblinkenlight 2014-09-20 18:43:27