void read_cells_and_create_start_system ( void ) { int dim,n,fail,*d,r,len,k,nbsols,mv; double *c; char ans = 'y'; fail = celcon_read_mixed_cell_configuration(); printf("\nReading a system to initialize the symbol table..."); fail = read_standard_target_system(); fail = celcon_dimension_of_points(&dim); printf("dimension of the lifted points : %d\n",dim); fail = show_mixture(dim,&r); fail = celcon_standard_random_coefficient_system(); printf("The random coefficient start system :\n"); fail = celcon_write_standard_random_coefficient_system(); fail = celcon_standard_polyhedral_homotopy(); fail = celcon_number_of_cells(&len); while (ans == 'y') { printf("Give a number to a mixed cell (<= %d) : ", len); scanf("%d",&k); fail = celcon_solve_standard_start_system(k,&nbsols); printf(" -> found %d start solutions from cell %d\n",nbsols,k); fail = celcon_mixed_volume(k,&mv); if (nbsols == mv) printf("#start solutions equals mixed volume %d, ok\n",mv); else printf("#start solutions does not equal mixed volume %d!!!\n",mv); printf("Do you wish to test another cell (y/n) "); scanf("%c",&ans); /* skip new line symbol */ ans = getchar(); } }
int compute_mixed_volume( void ) { int fail,mv,len,dim,r; fail = syscon_read_standard_system(); printf("\nThe system in the container : \n"); fail = syscon_write_standard_system(); fail = mixed_volume(&mv); printf("\nThe mixed volume : %d\n",mv); fail = celcon_number_of_cells(&len); printf("\nnumber of mixed cells : %d\n",len); fail = celcon_dimension_of_points(&dim); printf("dimension of the lifted points : %d\n",dim); fail = show_mixture(dim,&r); }
void read_and_retrieve ( void ) { int n,fail,*d,r; double *c; int len,dim; char ans; fail = celcon_read_mixed_cell_configuration(); printf("Do you wish to see the cells ? (y/n) "); ans = getchar(); if(ans == 'y') fail = celcon_write_mixed_cell_configuration(); fail = celcon_number_of_cells(&len); printf("\nnumber of mixed cells : %d\n",len); fail = celcon_dimension_of_points(&dim); printf("dimension of the lifted points : %d\n",dim); fail = show_mixture(dim,&r); fail = write_lifted_supports(dim); fail = query_cell(dim,r); }
void read_cells_and_solve_start_system ( void ) { int fail,dim,r,len,prcs; fail = celcon_read_mixed_cell_configuration(); printf("\nReading a system to initialize the symbol table..."); fail = read_standard_target_system(); fail = define_output_file(); fail = celcon_dimension_of_points(&dim); printf("dimension of the lifted points : %d\n",dim); fail = show_mixture(dim,&r); fail = celcon_number_of_cells(&len); printf("number of cells in the configuration : %d\n",len); prcs = prompt_for_precision(); if(prcs == 0) solve_standard_start_system(len); else if(prcs == 1) solve_dobldobl_start_system(len); else if(prcs == 2) solve_quaddobl_start_system(len); else printf("invalid precision level\n"); }
void distribute_cells ( int myid, int np, int nspt, int dim, int *nbpaths ) { int nbcell,*cell,nbsols,i,j,k,left[np],L,R,*m,sn,mysolnum; int count,labSize,cnt,dest; MPI_Status status; MPI_Comm com = MPI_COMM_WORLD; int length[nspt],*labels ; int fail,A[2],n; double normal[dim],sol[2*(dim-1)+5],*c; lisStack *s; int *a,*b; n=dim-1;A[0]=n; if(myid == 0) { fail=celcon_number_of_cells(&nbcell); /* get the number of cells */ cell=(int*)calloc(nbcell,sizeof(int)); for(i=0; i<nbcell; i++) fail = celcon_mixed_volume(i+1,&cell[i]); nbsols=0; for(i=0; i<nbcell; i++) nbsols=nbsols+cell[i]; if(v>0) printf("The number cells are %d\n",nbcell); if(v>0) print_cell(nbcell,cell); if(v>0) printf("The total solutions are %d\n",nbsols); } MPI_Bcast(&nbsols,1,MPI_INT,0,com); if(myid == 0) { if(v>0) printf("\n"); left[0] = 0; for(i=1; i<np; i++) if(i <= (nbsols%(np-1))) left[i] = nbsols/(np-1)+1; else left[i] = nbsols/(np-1); if(v>0) printf("left:"); if(v>0) Print_Integer_Array(np,left); } MPI_Scatter(left,1,MPI_INT,&mysolnum,1,MPI_INT,0,com); if(myid == 0) { fail = celcon_number_of_points_in_cell(1,nspt,length); labSize=0; for(i=0; i<nspt; i++) labSize = labSize+length[i]; labSize = 1+nspt+labSize; } MPI_Bcast(&labSize,1,MPI_INT,0,MPI_COMM_WORLD); labels = (int*)calloc(labSize,sizeof(int)); m=(int*)calloc(3,sizeof(int)); if(myid==0) { L=1; R=np-1; for(i=0; i<nbcell; i++) { m[0] = i+1; m[2] = labSize; celcon_retrieve_mixed_cell(dim,nspt,i+1,labels,normal); sn=1; while(cell[i]!=0) { if(cell[i]>=left[L]) { m[1] = left[L]; m[2] = sn; MPI_Send(&m[1],2,MPI_INT,L,SEND_CELL,com); /* if(v>0) printf("%2d paths from cell %d is sending to node %d\n", m[1],m[0],L); */ MPI_Send(labels,labSize,MPI_INT,L,SEND_SUPP,com); MPI_Send(normal,dim,MPI_DOUBLE,L,SEND_NORMAL,com) ; cell[i] = cell[i]-left[L]; sn = sn+left[L]; L++; } else if(cell[i]>=left[R]) { m[1] = left[R]; m[2] = sn; MPI_Send(&m[1],2,MPI_INT,R,SEND_CELL,com); /* if(v>0) printf("%2d paths from cell %d is sending to node %d\n", m[1],m[0],R); */ MPI_Send(labels,labSize,MPI_INT,R,SEND_SUPP,com); MPI_Send(normal,dim,MPI_DOUBLE,R,SEND_NORMAL,com) ; cell[i] = cell[i]-left[R]; sn = sn+left[R]; R--; } else { m[1] = cell[i]; m[2] = sn; MPI_Send(&m[1],2,MPI_INT,R,SEND_CELL,com); /* if(v>0) printf("%2d paths from cell %d is sending to node %d\n", m[1],m[0],R); */ MPI_Send(labels,labSize,MPI_INT,R,SEND_SUPP,com); MPI_Send(normal,dim,MPI_DOUBLE,R,SEND_NORMAL,com); left[R]=left[R]-cell[i]; sn = sn+cell[i]; cell[i]=0; } } } if(v>0) printf("****************************************************\n"); printf("writing random coefficient system and its solutions to file\n"); fail = celcon_write_random_coefficient_system(); fail = solcon_write_solution_dimensions_to_defined_output_file(nbsols,n); cnt = 0; for(k=1; k<=nbsols; k++) { MPI_Recv(&A[1],1,MPI_INT,MPI_ANY_SOURCE,SEND_MUL, MPI_COMM_WORLD,&status); MPI_Recv(sol,2*n+5,MPI_DOUBLE,MPI_ANY_SOURCE,SEND_SOL, MPI_COMM_WORLD,&status); fail = solcon_write_next_solution_to_defined_output_file (&cnt,n,A[1],sol); } *nbpaths = nbsols; } /* myid=0 finish */ else { *nbpaths = mysolnum; if(v>0) printf("Node %d has %d paths\n",myid,mysolnum); s=(lisStack*)calloc(1,sizeof(lisStack)); ls_init(s); count = 0; sn = 0; while(count < mysolnum) { MPI_Recv(&m[1],2,MPI_INT,0,SEND_CELL,com,&status); sn++; m[0] = sn; ls_push(s,m); count = count+m[1]; /* if(v>0) printf("Node %d is receving %2d paths from cell %d\n", myid,m[1],m[0]); */ MPI_Recv(labels,labSize,MPI_INT,0,SEND_SUPP,com,&status) ; MPI_Recv(normal,dim,MPI_DOUBLE,0,SEND_NORMAL,com,&status) ; fail = celcon_append_mixed_cell(dim,nspt,labSize,labels,normal); } fail = celcon_create_polyhedral_homotopy(); for(i=1; i<=sn; i++) { m = ls_cur(s); fail = celcon_solve_start_system(m[0],&R); if(fail == 1) { printf("Solving start system failed.\n"); printf("Node %d skips cell %d with volume %d...\n",myid,m[0],R); } else { /* printf("found %d start solutions from cell %d\n",R,m[0]); */ fail=celcon_mixed_volume(m[0],&L); /* if(R==L) printf("#start solutions equals mixed volume %d, OK\n",L); else printf("#start solutions not equals mixed volume %d!!!, \n",L); */ for(j=m[2]; j<m[1]+m[2]; j++) { fail = celcon_track_solution_path(m[0],j,0); fail = solcon_clear_solutions(); fail = celcon_copy_target_solution_to_container(m[0],j-m[2]+1); fail = solcon_retrieve_solution(n,1,&A[1],sol); MPI_Send(&A[1],1,MPI_INT,0,SEND_MUL,MPI_COMM_WORLD); MPI_Send(sol,2*n+5,MPI_DOUBLE,0,SEND_SOL,MPI_COMM_WORLD); } } ls_pop(s); } } /* end else */ /* MPI_Barrier(com); */ if(myid == 0) free(cell); else free(s); free(labels); free(m); }