int query_cell ( int n, int r ) { int k,fail,*b,i,j,mv,nl[r],kk; double *c,normal[n],pt[n]; printf("\nGive a cell number : "); scanf("%d", &k); fail = celcon_get_inner_normal(n,k,normal); if (fail==1) printf("an error happened...\n"); else { printf("inner normal for cell %d :\n", k); for(i=0;i<n;i++) printf("%.15le\n", normal[i]); fail = celcon_number_of_points_in_cell(k,r,nl); printf("number of points in supports :"); for(i=0;i<r;i++) printf(" %d",nl[i]); printf("\n"); printf("points in the supports :\n"); for(i=0;i<r;i++) { for(j=0;j<nl[i];j++) { fail = celcon_get_point_in_cell(n,k,i+1,j+1,pt); for(kk=0; kk<n-1; kk++) printf(" %d",(int) pt[kk]); printf(" %.15le\n", pt[n-1]); } } fail = celcon_mixed_volume(k,&mv); printf("mixed volume : %d\n",mv); { int cl[1+r+2*n]; double inner_normal[n]; fail = celcon_retrieve_mixed_cell(n,r,k,cl,inner_normal); printf("the inner normal for cell %d : \n", k); for(i=0; i<n; i++) printf(" %.15le\n", inner_normal[i]); printf("total number of points in supports : %d\n",cl[0]); printf("number of points in supports : "); for(i=1; i<=r; i++) printf(" %d", cl[i]); printf("\n"); printf("labels of points : "); kk=r; for(i=1; i<=r; i++) { for(j=0; j<cl[i]; j++) printf(" %d", cl[++kk]); printf(" | "); } printf("\n"); } } return fail; }
int query_cell ( int n, int r, int *cellnb, int tosolve ) { int k,fail,*b,i,j,mv,nl[r],kk,mvcell; double *c,normal[n],pt[n]; char ch; printf("Give a cell number : "); scanf("%d", &k); if(tosolve == 1) { fail = celcon_standard_random_coefficient_system(); fail = celcon_standard_polyhedral_homotopy(); } fail = celcon_get_inner_normal(n,k,normal); if (fail==1) printf("an error happened...\n"); else { *cellnb = k; printf("inner normal for cell %d :\n", k); for(i=0; i<n; i++) printf("%.15le\n", normal[i]); fail = celcon_number_of_points_in_cell(k,r,nl); printf("number of points in supports :"); for(i=0; i<r; i++) printf(" %d",nl[i]); printf("\n"); scanf("%c",&ch); /* get previous new line symbol */ printf("Hit enter to continue."); scanf("%c",&ch); /* catch new line symbol */ printf("points in the supports :\n"); for(i=0; i<r; i++) { for(j=0; j<nl[i]; j++) { fail = celcon_get_point_in_cell(n,k,i+1,j+1,pt); for(kk=0; kk<n-1; kk++) printf(" %d",(int) pt[kk]); printf(" %.15le\n", pt[n-1]); } } fail = celcon_mixed_volume(k,&mv); printf("mixed volume : %d\n",mv); printf("Hit enter to continue."); scanf("%c",&ch); /* catch new line symbol */ if(tosolve == 1) { fail = celcon_solve_standard_start_system(k,&mvcell); printf("The number of solutions : %d\n", mvcell); printf("Hit enter to continue."); scanf("%c",&ch); /* catch new line symbol */ } { int cl[1+r+2*n]; double inner_normal[n]; fail = celcon_retrieve_mixed_cell(n,r,k,cl,inner_normal); printf("the inner normal for cell %d : \n", k); for(i=0; i<n; i++) printf(" %.15le\n", inner_normal[i]); printf("total number of points in supports : %d\n",cl[0]); printf("number of points in supports : "); for(i=1; i<=r; i++) printf(" %d", cl[i]); printf("\n"); printf("labels of points : "); kk=r; for(i=1; i<=r; i++) { for(j=0; j<cl[i]; j++) printf(" %d", cl[++kk]); printf(" | "); } printf("\n"); printf("Hit enter to continue."); scanf("%c",&ch); /* catch new line symbol */ } } return fail; }
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); }