#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
struct ags{
long int **mat1;
long int **mat2;
int *semafor;
int rowsDone;
};
void *thread_multiply(void*);
int main(int args, char** argv){
int mat1x;
int mat1y;
int mat2x;
int mat2y;
int threadsAmount;
printf("Podaj szerokosc pierwszej macierzy: ");
scanf("%i", &mat1x);
printf("Podaj wysokosc pierwszej macierzy: ");
scanf("%i", &mat1y);
printf("Podaj szerokosc drugiej macierzy: ");
scanf("%i", &mat2x);
printf("Podaj wysokosc drugiej macierzy: ");
scanf("%i", &mat2y);
printf("Podaj ilosc watkow: ");
scanf("%i", &threadsAmount);
if(mat1x != mat2y){
printf("Musisz podac odpowiednie macierze!");
return;
}
struct ags* strAgs;
int i;
int j;
for(i = 0; i < mat1y; i++){
for(j = 0; j < mat1x; j++){
strAgs->mat1[i][j] = random();
}
}
for(i = 0; i < mat2y; i++){
for(j = 0; j < mat2x; j++){
strAgs->mat2[i][j] = random();
}
}
for(j = 0; j < mat2x; j++){
strAgs->semafor[j] = 0;
}
strAgs->rowsDone = mat2x;
pthread_t threadsArray[threadsAmount];
for(i = 0; i < threadsAmount; i++){
if(pthread_create(&threadsArray[i], NULL, thread_multiply, (void*) strAgs)) {
fprintf(stderr, "Error creating thread\n");
return 1;
}
}
for(i = 0; i < threadsAmount; i++){
if(pthread_join(threadsArray[i], NULL)) {
fprintf(stderr, "Error joining thread\n");
return 1;
}
}
}
void *thread_multiply(void* ptr) {
struct ags* agsStruct = (struct ags*) ptr;
while(agsStruct->rowsDone > 0){
printf("woho\n");
agsStruct->rowsDone--;
}
};
여기에 코드가 있습니다. 이제 질문입니다. 임 스레드에서 행렬을 곱하는 프로그램을 만들려고. 문제는 이제 실행하려고 할 때 오류가 발생했습니다. 괜찮아요, 단지 내가 begginng에서 5 ints를 입력하면 그냥 충돌, 그리고 난 왜 찾을 수 없습니다. 어떤 생각을 어떻게 수리 할 수 있습니까?행렬을 곱하는 C 프로그램에서 오류를 찾는 방법
아. 하지만 mat1x mat1y 등의 크기가 필요합니다. 가능합니까? –
@ user3552292 예. 나는 조금 살펴볼 것이다. – DevNull
위대한,하지만 난 그것을 시도 alrdy. 여전히 오류. 프로그램은 struct 다음에 하나의 printf를 출력하지 않습니다. –