구조를 사용하여 이러한 행렬을 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]
이 잘못된 : 참조 연산자 (예 : 별표 *
)가 필요하지 않습니다이 포인터에 대한 포인터이기 때문에
고맙습니다. 저에게 도움이 될 것입니다. – djst2d
@ djst2d 환영합니다! 이것을 시험해보고 효과가 있는지보십시오. 그렇다면 옆에있는 회색 체크 표시를 클릭하여 대답을 수락하십시오. 이렇게하면 스택 오버플로에 대한 새로운 배지가 생기고 다른 사람들에게 문제가 해결되었음을 알릴 수 있습니다. – dasblinkenlight