2014-09-20 3 views
2

구조를 사용하여 이러한 행렬을 pthread에 전달하려고합니다. 구조C의 구조체를 통해 행렬의 주소를 전달하는 방법은 무엇입니까?

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; 

스레드에 의해 실행되는 루틴을 통과

매트릭스 할당

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

. *>와 - 루틴 시도가

td->*C[i][j]+=td->*A[i][k]*td->(*B[k][j]); 

에서이 행렬을 찾을 수없는 실행할 때

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

문제는 내가 그 사이에 뭔가를 기대 말하는 오류가 발생합니다.

도움 주셔서 감사합니다.

typedef struct { 
    int start; 
    int end; 
    double **A; 
    double **B; 
    double **C; 
} thread_data_t; 

구문 td->*C[i][j]이 잘못된 : 참조 연산자 (예 : 별표 *)가 필요하지 않습니다이 포인터에 대한 포인터이기 때문에

답변

1

첫째, 매트릭스 구성원의 선언은 두 개의 별표를 가질 필요가

td->C[i][j] += (td->A[i][k]) * (td->B[k][j]); 

참고 : 대괄호가 하나의 간접 수준을 감소 [] 때문에,이 문제와 관련이없는,하지만 경우에 당신은 포인터에 저장 역 참조해야 할 때 struct의 경우 식의 결과에 별표를 적용합니다 (예 : *(td->ptrC[i][j])). ->의 우선 순위가 높기 때문에 괄호는 필요하지 않지만 어쨌든 무슨 일이 일어나는지 설명하기 위해 괄호를 넣었습니다.

+0

고맙습니다. 저에게 도움이 될 것입니다. – djst2d

+0

@ djst2d 환영합니다! 이것을 시험해보고 효과가 있는지보십시오. 그렇다면 옆에있는 회색 체크 표시를 클릭하여 대답을 수락하십시오. 이렇게하면 스택 오버플로에 대한 새로운 배지가 생기고 다른 사람들에게 문제가 해결되었음을 알릴 수 있습니다. – dasblinkenlight

관련 문제