int read_mixed_cell ( int r, int n ) { /* a mixed cell is represented by three vectors: 1) a[0] = r, a[1] = n, and a[2] = length of vector b; 2) b[0] = total number of points in the cell b[i] = gives the points in the i-th support; b[1+r+k] = the label for the k-th lifted point in the cell; 3) c = an n-vector, is the inner normal */ int a[3],*b,cnt[r],i,j,k,fail,sum; double c[n]; printf("Give the inner normal (%d-vector) : ",n); for(i=0; i<n; i++) scanf("%lf",&c[i]); printf("Reading the number of points in each support...\n"); a[0] = r; a[1] = n; sum = 0; for(i=0; i<r; i++) { printf(" #points in support %d : ",i+1); scanf("%d",&cnt[i]); sum += cnt[i]; } a[2] = 1+r+sum; b = (int*)calloc(a[2],sizeof(int)); b[0] = a[2]; for(i=0; i<r; i++) b[i+1] = cnt[i]; printf("Reading the labels for each support...\n"); k = r+1; for(i=0; i<r; i++) { printf(" give %d labels for support %d : ",cnt[i],i+1); for(j=0; j<cnt[i]; j++) scanf("%d",&b[k++]); } fail = celcon_append_mixed_cell(n,r,b[0],b,c); 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); }