int main() { /* Chan, Joey, JMCSC, ync12 */ int m = 0, N; int should_stop = 0; clock_t start, end; double ***result; double time_taken; printf(" N Result Time taken \n"); printf("--------- -------------------- ------------\n"); for (N = 32; N <= 96; N+= 32) { start = clock(); result = calculate_gravitational_potential(N); end = clock(); time_taken = (double) (end - start) / CLOCKS_PER_SEC; printf("%9d %20.8f %12.6f\n", N, result[N/2][N/2][N/2], time_taken); free_cube(result, N); } while (!should_stop) { int i; for (i = 4; i <= 6; i++) { N = i*(int)pow(2, 5+m); start = clock(); result = calculate_gravitational_potential(N); end = clock(); time_taken = (double) (end - start) / CLOCKS_PER_SEC; printf("%9d %20.8f %12.6f\n", N, result[N/2][N/2][N/2], time_taken); free_cube(result, N); if (time_taken > 600) { should_stop = 1; break; } } m++; } return 0; }
/* complement -- compute the complement of T */ pcover complement(pset *T) /* T will be disposed of */ { register pcube cl, cr; register int best; pcover Tbar, Tl, Tr; int lifting; static int compl_level = 0; if (debug & COMPL) debug_print(T, "COMPLEMENT", compl_level++); T = compl_special_cases(T, &Tbar); if (T != NULL){ /* Allocate space for the partition cubes */ cl = new_cube(); cr = new_cube(); best = binate_split_select(T, cl, cr, COMPL); /* Complement the left and right halves */ Tl = complement(scofactor(T, cl, best)); Tr = complement(scofactor(T, cr, best)); if (Tr->count*Tl->count > (Tr->count+Tl->count)*CUBELISTSIZE(T)) { lifting = USE_COMPL_LIFT_ONSET; } else { lifting = USE_COMPL_LIFT; } Tbar = compl_merge(T, Tl, Tr, cl, cr, best, lifting); free_cube(cl); free_cube(cr); free_cubelist(T); } if (debug & COMPL) debug1_print(Tbar, "exit COMPLEMENT", --compl_level); return Tbar; }
bool Is_Group_Connect(pcover WSS, pset group, pset inp, int *inp_ind) { register pset r=new_cube(), mask=new_cube(); register int ind; register bool result; ind = Get_Var_Ind(group, 0); Generate_Mask(mask, inp); if (set_andp(r, mask, GETSET(WSS, ind))) result = TRUE; else result = FALSE; *inp_ind = Get_Var_Pos(r, 0); free_cube(r); free_cube(mask); return result; }
/* primes_consensus -- generate primes using consensus */ pcover primes_consensus(pset *T) /* T will be disposed of */ { register pcube cl, cr; register int best; pcover Tnew, Tl, Tr; if (primes_consensus_special_cases(T, &Tnew) == MAYBE) { cl = new_cube(); cr = new_cube(); best = binate_split_select(T, cl, cr, COMPL); Tl = primes_consensus(scofactor(T, cl, best)); Tr = primes_consensus(scofactor(T, cr, best)); Tnew = primes_consensus_merge(Tl, Tr, cl, cr); free_cube(cl); free_cube(cr); free_cubelist(T); } return Tnew; }
static bool primes_consensus_special_cases(pset *T, pset_family *Tnew) /* will be disposed if answer is determined */ /* returned only if answer determined */ { register pcube *T1, p, ceil, cof=T[0]; pcube last; pcover A; /* Check for no cubes in the cover */ if (T[2] == NULL) { *Tnew = new_cover(0); free_cubelist(T); return TRUE; } /* Check for only a single cube in the cover */ if (T[3] == NULL) { *Tnew = sf_addset(new_cover(1), set_or(cof, cof, T[2])); free_cubelist(T); return TRUE; } /* Check for a row of all 1's (implies function is a tautology) */ for(T1 = T+2; (p = *T1++) != NULL; ) { if (full_row(p, cof)) { *Tnew = sf_addset(new_cover(1), cube.fullset); free_cubelist(T); return TRUE; } } /* Check for a column of all 0's which can be factored out */ ceil = set_save(cof); for(T1 = T+2; (p = *T1++) != NULL; ) { INLINEset_or(ceil, ceil, p); } if (! setp_equal(ceil, cube.fullset)) { p = new_cube(); (void) set_diff(p, cube.fullset, ceil); (void) set_or(cof, cof, p); free_cube(p); A = primes_consensus(T); foreach_set(A, last, p) { INLINEset_and(p, p, ceil); }
/* setdown_cube -- free memory allocated for the cube/cdata structs (free's all but the part_size array) (I wanted to call this cube_setdown, but that violates the 8-character external routine limit on the IBM !) */ void setdown_cube() { register int i, var; FREE(cube.first_part); FREE(cube.last_part); FREE(cube.first_word); FREE(cube.last_word); FREE(cube.sparse); free_cube(cube.binary_mask); free_cube(cube.mv_mask); free_cube(cube.fullset); free_cube(cube.emptyset); for(var = 0; var < cube.num_vars; var++) free_cube(cube.var_mask[var]); FREE(cube.var_mask); for(i = 0; i < CUBE_TEMP; i++) free_cube(cube.temp[i]); FREE(cube.temp); FREE(cdata.part_zeros); FREE(cdata.var_zeros); FREE(cdata.parts_active); FREE(cdata.is_unate); cube.first_part = cube.last_part = (int *) NULL; cube.first_word = cube.last_word = (int *) NULL; cube.sparse = (int *) NULL; cube.binary_mask = cube.mv_mask = (pcube) NULL; cube.fullset = cube.emptyset = (pcube) NULL; cube.var_mask = cube.temp = (pcube *) NULL; cdata.part_zeros = cdata.var_zeros = cdata.parts_active = (int *) NULL; cdata.is_unate = (bool *) NULL; }