コード例 #1
0
ファイル: sieve.c プロジェクト: albinoBandicoot/nsieve
void add_polygroup_relations (poly_group_t *pg, nsieve_t *ns){
	/* now we get to pick our victim. It must be a full relation (though I guess theoretically if 
	 * there were no fulls but two partials from this poly group shared a cofactor it could be used, 
	 * but that's more thinking and debugging than it's worth, especially since if we're finding 
	 * groups without full relations, our parameters are way off.
	 *
	 * Theoretically, it would probably be best to pick the sparsest relation as the victim, but 
	 * we'll just pick the first one.
	*/
	for (int i=0; i < pg->nrels; i++){
		if (pg -> relns[i]->cofactor == 1){
			if (fl_check (pg->relns[i], ns)){
				pg->victim = pg->relns[i];
				break;
			}
		}
	}

	/* Since we will me modifying state in the nsieve_t, which is the same for all threads, 
	 * we need to acquire the lock first to make sure we don't have multiple threads writing
	 * all over each other. */
	pthread_mutex_lock (&ns->lock);

	if (pg->victim != NULL){	// we found a full relation
		for (int i=0; i < pg->nrels; i++){
			if (ns->nfull >= ns->rels_needed) {	// we're done sieving.
				ns->info_npg ++;
				ns->info_npoly += ns->bvals;
				pthread_mutex_unlock (&ns->lock);
				return;	
			}
			if (pg->relns[i] == pg->victim) continue;	// we don't want to add the victim to the list.
			if (!fl_check (pg->relns[i], ns)) continue;	// don't add bad relations
			if (pg->relns[i]->cofactor == 1){		// full relation
				matrel_t *m = &ns->relns[ns->nfull];
				m -> r1 = pg->relns[i];
				m -> r2 = NULL;
				fl_concat  (m->r1, pg->victim);
				ns->nfull ++;
			} else {
				ht_add (&ns->partials, pg->relns[i]);
			}
		}
	} else {
		// we did not find one. This is not good, but not an error either - we were just unlucky. 
		// However, we should probably be doing either larger sieve intervals or a larger k or something. 
		printf("There are no full relations for this polygroup! We must throw away the partials.\n");
	}
	ns->info_npg ++;
	ns->info_npoly += ns->bvals;
	pthread_mutex_unlock (&ns->lock);
}
コード例 #2
0
ファイル: freelist.c プロジェクト: bobzhang/ocaml
void caml_fl_init_merge (void)
{
  last_fragment = NULL;
  caml_fl_merge = Fl_head;
#ifdef DEBUG
  fl_check ();
#endif
}