I need huge help. I need to do a C program in which I compute the diagonals of an array using Threads as per the statements:
AsIwastold,Ishouldpassthevalueofthediagonalandthejump(diagonalchange)asparameters,butIdonotknowwhattodowiththosevalues.
ThefollowingisthecodethatIhavebeenabletodosofar(thisisincompletebecauseIdonotknowhowtodothefunctiontoaddthediagonals):
NOTE:Itookthefunctionsthatgeneratethefilewiththevaluesofthearrayandthefunctionthatassignsthesevaluestothearraysothecodebecomescleanerandeasiertounderstand.
typedefstruct{intdiag=0;intsalto;}ST;STv;structparam*arg;void*somarMatriz(void*args){ST*in=(ST*)args;intx=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++;}}intmain(){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");
}