void sequencial(int id_matriz){ struct timeval start,end; int i=0; //MATRIZES *matrizes = inicializaVariaveis(id_matriz,0); MATRIZES *matrizes = NULL; char name_arq[37]; double tempo = 0; double tempo_aux=0; int n_interacoes=-1; double rowtest =0.0; for(i = 0 ; i < 10 ; ++i){ matrizes = inicializaVariaveis(id_matriz,0); sprintf(name_arq,"out/%d/seq/%d_seqOp%d.txt",matrizes->number_matriz, matrizes->number_matriz,i); FILE *arq_save = NULL; if( (arq_save=fopen(name_arq,"w")) == NULL){ printf("File name_arq errou ao abir\n"); } gettimeofday(&start,NULL); inicializaMetodo(matrizes); n_interacoes = inicioInteracaoSequencial(matrizes,arq_save); rowtest = rowTest(matrizes); gettimeofday(&end,NULL); tempo_aux =( ((double) ( ((end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec))))/1000000); tempo +=tempo_aux; writeEndX(matrizes,arq_save); fprintf(arq_save, "Numero de Interacoes: %d\n",n_interacoes ); fprintf(arq_save, "RowTest: %d => [%lf] =? %lf\n", matrizes->J_ROW_TEST, rowtest , matrizes->ROW_TEST[matrizes->J_ORDER]); fprintf(arq_save, "Tempo de Execucao: %lf\n",tempo_aux ); fclose(arq_save); if(i != 9) freeAll(&matrizes); } printf("---------------------------------------------------------\n"); printf("Iterations: %d\n", n_interacoes); printf("RowTest: %d => [%lf] =? %lf\n", matrizes->J_ROW_TEST, rowtest , matrizes->ROW_TEST[matrizes->J_ORDER]); printf("Tempo medio: %lf",tempo/10); printf("\n-------------------------------------------------------\n"); freeAll(&matrizes); }
int main() { int grid = 0; int runtime = 0; int ar[9][9]; int row = 0; int column = 0; int c = 2; int d = 2; int e = 2; //input how many puzzle will be check scanf("%d",&grid); //input files from provided input files while(runtime != grid) // check and see if the program used every game given { //nested for loop to fill in the sudokode array for (row = 0; row<9;row++) { for(column = 0; column< 9;column++) { //input the number to a 2D array scanf("%d",&(ar[row][column])); } } //increase run time by one after run through the loop once runtime++; // set c,d ,e to the return value each test give c = rowTest(ar); d = columnTest(ar); e = boxTest(ar); // check if the puzzle had pass the row, column and box test if( (c==1) && (d==1) && (e==1) ) { printf("YES\n"); } else printf("NO\n"); }//end of while loop return 0; }
int boxTest(int ar[9][9]) { int arr2[9][9]; int i,j,k = 0,l; // convert 3x3 boxes into row of another array for(l = 0;l < 9 ;l++) { for(i =(3*(l/3));i<(3*( (l/3)+1) );i++) { for(j= (3* (l%3) ); j<(3*( ( l % 3 ) + 1 ) ) ; j++) { arr2[l][k] = ar[i][j]; k++; } } k = 0; } //call rowtest function to check for duplicate in box return rowTest(arr2); }
void concorrente(int id_matriz,int n_threads){ struct timeval start,end; MATRIZES *matrizes = NULL; int i; char name_arq[37]; double tempo = 0; double tempo_aux=0; int n_interacoes; double rowtest =0.0; for(i = 0 ; i < 10 ; ++i){ printf("interacao: %d\n",i); matrizes = inicializaVariaveis(id_matriz,n_threads); sprintf(name_arq,"out/%d/conc%d/%d_conc%dOp%d.txt",matrizes->number_matriz, matrizes->n_threads,matrizes->number_matriz,matrizes->n_threads,i); FILE *arq_save = fopen(name_arq,"w"); gettimeofday(&start,NULL); inicializaMetodo(matrizes); n_interacoes = inicioInteracaoConcorrente(matrizes,arq_save); rowtest = rowTest(matrizes); gettimeofday(&end,NULL); tempo_aux =( ((double) ( ((end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec))))/1000000); tempo +=tempo_aux; writeEndX(matrizes,arq_save); fprintf(arq_save, "Numero de Interacoes: %d\n", n_interacoes ); fprintf(arq_save, "RowTest: %d => [%lf] =? %lf\n", matrizes->J_ROW_TEST, rowtest , matrizes->ROW_TEST[matrizes->J_ORDER]); fprintf(arq_save, "Tempo de Execucao: %lf\n",tempo_aux ); fclose(arq_save); if(i !=9) freeAll(&matrizes); } printf("---------------------------------------------------------\n"); printf("Iterations: %d\n",n_interacoes ); printf("RowTest: %d => [%lf] =? %lf\n", matrizes->J_ROW_TEST, rowtest , matrizes->ROW_TEST[matrizes->J_ORDER]); printf("Tempo medio: %lf\n",tempo/10); printf("-------------------------------------------------------\n\n"); freeAll(&matrizes); }