void* consumidor(void *n) { int ene = *(int*) n; int i; char * senha = (char*) malloc(sizeof(char)*TAM_SENHA); char * aux = (char*) malloc(sizeof(char)*TAM_SENHA); if(ene == 0){ for(i=0;i<TAM_SENHA;i++) senha[i] = '0'; }else{ sprintf(aux, "%d", ene); int conta = strlen(aux) - TAM_SENHA; for(i=0;i<conta;i++) senha[i] = '0'; strcat(senha,aux); } senha[TAM_SENHA] ='\0'; for(i=0;(i<divisao+1) && !encontrada; i++){ if(testa_senha(hashEntrada, senha) == 0){ // deu certo encontrada = 1; return NULL; }else{ if(!incrementa_senha(senha)){ encontrada = 0; return NULL; } } } return NULL; }
int main(int argc, char *argv[]) { int i, inicio, fim; char senha[TAM_SENHA + 1]; char **buffer; int my_rank, comm_sz; int n_local; MPI_Comm comm = MPI_COMM_WORLD; if (argc != 2) { printf("Uso: %s <hash>", argv[0]); return 1; } MPI_Init(NULL,NULL); MPI_Comm_size(MPI_COMM_WORLD, &comm_sz); MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); //aloca a quantidade de possibilidades no buffer buffer = (char **) calloc( TAM_POSSIBILIDADES, sizeof(char *)); //aloca o primeiro vetor e o preenche com a primeira senha buffer[0] = (char *) calloc(TAM_SENHA + 1, sizeof(char *)); for(i = 0; i< TAM_SENHA; i++){ buffer[0][i] = 'a'; } buffer[0][TAM_SENHA] = '\0'; strcpy(senha, buffer[0]); //aloca os outros vetores enquanto preenche com o restante das senhas for (i = 1; i < TAM_POSSIBILIDADES + (TAM_POSSIBILIDADES % comm_sz); i++){ buffer[i] = (char *) calloc(TAM_SENHA + 1 , sizeof(char)); incrementa_senha(senha); strcpy(buffer[i], senha); } n_local = TAM_POSSIBILIDADES / comm_sz; inicio = my_rank * n_local; fim = inicio + n_local; strcpy(senha, buffer[0]); i = inicio; while (i < fim) { testa_senha(argv[1], senha); i++; strcpy(senha, buffer[i]); } MPI_Barrier(comm); return 0; }