4
I need a lot of help. I need to make a program in C in which calculate the diagonals of an array using Threads as stated:
As directed, I must pass the value of diagonal and jump (diagonal change) as parameters, but I do not know what to do with these values.
Follow the code I have been able to do so far (this incomplete because I do not know how to proceed in the function to add the diagonals):
NOTE: I took the functions that generate the file with the values of the matrix and the function that assigns these values to the matrix to make the code cleaner and easier to understand.
typedef struct{
int diag=0;
int salto;
}ST;
ST v;
struct param *arg;
void *somarMatriz(void *args){
ST * in = (ST *) args;
int x=0, y=0;
result = (float *) malloc((l+c-1)*sizeof(float));
x=0;
for(i=; i<l+c-1; i++){
result[i]=0;
}
for(i=l-1; i>=0; i--){
x = y;
for(j=0; j<c; j++){
result[x] += mat[i][j];
x++;
}
y++;
}
}
int main (){
printf("Entre com o numero de linhas da matriz: \n");
scanf("%d", &l);
printf("Entre com o numero de colunas da matriz: \n");
scanf("%d", &c);
printf("Entre com o quantidade de Threads desejada:\n");
scanf("%d", &arg.salto);
gerarArquivo(l, c);
gerarMatriz(l, c);
pthread_t threads[T];
pthread_attr_t attr;
int rc;
long t;
void *status;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
for(t=0; t<T; t++){
rc = pthread_create(&threads[t], NULL, somarMatriz, (void*)&v);
if (rc){
printf("ERRO");
exit(-1);
}
}
pthread_exit((void *)NULL);
printf("\n\n");
printf("Resultados:\n");
for(i=0; i<l+c-1; i++){
printf("%d\t", result[i]);
}
printf("\n");
}
Here is an example of how to Thread Pool in C: https://stackoverflow.com/questions/8357955/windows-api-thread-pool-simple-example
– Gustavo Dambros