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