// When a backup is ongoing, use this to add newly complete candidates. int candidate_add_fresh(const char *path, const char *directory, struct scores *scores) { const char *cp=NULL; struct candidate *candidate=NULL; if(!(candidate=candidates_add_new())) goto error; cp=path+strlen(directory); while(cp && *cp=='/') cp++; if(!(candidate->path=strdup_w(cp, __func__))) goto error; switch(candidate_load(candidate, path, scores)) { case CAND_RET_PERM: goto error; case CAND_RET_TEMP: // Had an error - try to carry on. Errors can happen // when loading a fresh candidate because the backup // process can move to the next phase and rename the // candidates. logp("Removing candidate.\n"); candidates_len--; sparse_delete_fresh_candidate(candidate); candidate_free(&candidate); // Fall through. case CAND_RET_OK: return 0; } error: candidate_free(&candidate); return -1; }
void cofact_next_algo(candidate_t *cand, int algo_idx) { int size, size_idx; cofact_algo_t *algo; cofact_queue_t *queue; if(cand->side >= sizeof(cand->rem) / sizeof(cand->rem[0])) { rel_count++; candidate_print(cand); candidate_free(cand); return; } if(mpz_cmp_ui(cand->rem[cand->side], 1) == 0) { cand->side++; cofact_next_algo(cand, 0); return; } size = mpz_sizeinbase(cand->rem[cand->side], 2); if(size <= cand_lpb[cand->side]) { candidate_add_factor_mpz(cand, cand->side, cand->rem[cand->side]); cand->side++; cofact_next_algo(cand, 0); return; } if(algo_idx >= n_cofact_algos) { candidate_free(cand); return; } size_idx = (size + 1) / SIZE_INCREMENT; if(size_idx > MPZ_SIZE_IDX) size_idx = MPZ_SIZE_IDX; algo = &cofact_algos[size_idx][algo_idx]; queue = algo->queue; queue->batch[queue->n_batch] = cand; queue->n_batch++; if(queue->n_batch >= COFACT_BATCH_SIZE) cofact_queue_algo(algo); return; }
END_TEST START_TEST(test_sparse_add_many) { struct sparse *sparse; uint64_t f0=0xFF11223344556699; uint64_t f1=0xFF11223344556677; uint64_t f2=0xFF11223344556688; struct candidate *candidate1; struct candidate *candidate2; struct candidate *candidate3; struct candidate *candidate4; struct candidate *candidate5; fail_unless((candidate1=candidate_alloc())!=NULL); fail_unless((candidate2=candidate_alloc())!=NULL); fail_unless((candidate3=candidate_alloc())!=NULL); fail_unless((candidate4=candidate_alloc())!=NULL); fail_unless((candidate5=candidate_alloc())!=NULL); fail_unless(!sparse_add_candidate(&f1, candidate1)); fail_unless(!sparse_add_candidate(&f1, candidate1)); fail_unless(!sparse_add_candidate(&f1, candidate2)); fail_unless(!sparse_add_candidate(&f2, candidate3)); fail_unless(!sparse_add_candidate(&f2, candidate4)); fail_unless(!sparse_add_candidate(&f2, candidate5)); // Try same again. fail_unless((sparse=sparse_find(&f0))==NULL); fail_unless((sparse=sparse_find(&f1))!=NULL); fail_unless(sparse->size==2); fail_unless(sparse->candidates[0]==candidate1); fail_unless(sparse->candidates[1]==candidate2); fail_unless((sparse=sparse_find(&f2))!=NULL); fail_unless(sparse->size==3); fail_unless(sparse->candidates[0]==candidate3); fail_unless(sparse->candidates[1]==candidate4); fail_unless(sparse->candidates[2]==candidate5); sparse_delete_all(); candidate_free(&candidate1); candidate_free(&candidate2); candidate_free(&candidate3); candidate_free(&candidate4); candidate_free(&candidate5); tear_down(); }
END_TEST START_TEST(test_sparse_add_one) { struct sparse *sparse; uint64_t f=0xFF11223344556677; struct candidate *candidate; fail_unless((candidate=candidate_alloc())!=NULL); fail_unless(!sparse_add_candidate(&f, candidate)); fail_unless((sparse=sparse_find(&f))!=NULL); fail_unless(sparse->size==1); fail_unless(sparse->candidates[0]==candidate); sparse_delete_all(); candidate_free(&candidate); fail_unless(!candidate); tear_down(); }