void broadcast(vrp_problem *vrp, int *tids, int jobs) { int s_bufid; if (jobs == 0) return; s_bufid = init_send(DataInPlace); send_int_array(&vrp->dist.wtype, 1); send_int_array(&vrp->vertnum, 1); send_int_array(&vrp->depot, 1); send_int_array(&vrp->capacity, 1); send_int_array(vrp->demand, (int)vrp->vertnum); if (vrp->dist.wtype != _EXPLICIT){ /* not EXPLICIT */ send_dbl_array(vrp->dist.coordx, vrp->vertnum); send_dbl_array(vrp->dist.coordy, vrp->vertnum); if ((vrp->dist.wtype == _EUC_3D) || (vrp->dist.wtype == _MAX_3D) || (vrp->dist.wtype == _MAN_3D)) send_dbl_array(vrp->dist.coordz, vrp->vertnum); } else{ /* EXPLICIT */ send_int_array(vrp->dist.cost, (int)vrp->edgenum); } msend_msg(tids, jobs, VRP_BROADCAST_DATA); freebuf(s_bufid); }
int user_send_lp_data(void *user, void **user_lp) { /* This gives you access to the user data structure. */ spp_problem *spp = (spp_problem *) user; col_ordered *m = spp->cmatrix; #if defined(COMPILE_IN_TM) && defined(COMPILE_IN_LP) spp_lp_problem *spp_lp = (spp_lp_problem *) calloc(1, sizeof(spp_lp_problem)); *user_lp = (void *) spp_lp; spp_lp->par = spp->lp_par; spp_lp->cmatrix = m; /* initialize some data structures in spp */ spp_init_lp(spp_lp); #else /* Here, we send that data using message passing and the rest is done in user_receive_lp_data() in the LP process */ send_char_array((char *)spp->lp_par, sizeof(spp_lp_params)); send_int_array(&m->colnum, 1); send_int_array(&m->rownum, 1); send_int_array(&m->nzcnt, 1); send_int_array(m->colnames, m->colnum); send_dbl_array(m->obj, m->colnum); send_int_array(m->matbeg, (m->colnum + 1)); send_char_array((char *)m->matind, m->nzcnt * sizeof(row_ind_type)); #endif return(USER_SUCCESS); }
int user_send_cg_data(void *user, void **user_cg) { spp_problem *spp = (spp_problem *)user; col_ordered *m = spp->cmatrix; int colnum = m->colnum; #if defined(COMPILE_IN_TM) && defined(COMPILE_IN_LP) && defined (COMPILE_IN_CG) spp_cg_problem *spp_cg = (spp_cg_problem *)calloc(1,sizeof(spp_cg_problem)); *user_cg = (void *) spp_cg; spp_cg->par = spp->cg_par; spp_cg->cmatrix = m; /* allocate space for tmp arrays */ spp_cg->tmp = (spp_cg_tmp *) calloc(1, sizeof(spp_cg_tmp)); spp_cg->tmp->itmp_m = (int *) malloc(m->rownum * ISIZE); spp_cg->tmp->istartmp_m = (int **) malloc(m->rownum * sizeof(int *)); spp_cg->tmp->cuttmp = (cut_data *) calloc(1, sizeof(cut_data)); /* initialize cg data structures */ spp_cg->fgraph = (frac_graph *) calloc(1, sizeof(frac_graph)); spp_cg->cfgraph = (frac_graph *) calloc(1, sizeof(frac_graph)); spp_cg->cm_frac = (col_ordered *) calloc(1, sizeof(col_ordered)); spp_cg->rm_frac = (row_ordered *) calloc(1, sizeof(row_ordered)); spp_cg->rm_frac->rmatbeg = (int *) malloc((m->rownum+1) * ISIZE); spp_cg->lgraph = (level_graph *) calloc(1, sizeof(level_graph)); allocate_var_length_structures(spp_cg, spp_cg->max_sol_length); /* cut collection is a local cut pool that contains the cuts that have been sent back to the lp */ spp_cg->cut_coll = (cut_collection *) calloc(1, sizeof(cut_collection)); spp_cg->cut_coll->max_size = 1000; spp_cg->cut_coll->cuts = (cut_data **) calloc(spp_cg->cut_coll->max_size, sizeof(cut_data *)); spp_cg->cut_coll->violation = (double *) malloc(spp_cg->cut_coll->max_size * DSIZE); spp_cg->cut_coll->mult = (int *) malloc(spp_cg->cut_coll->max_size * ISIZE); #else int info; send_char_array((char *)spp->cg_par, sizeof(spp_cg_params)); send_int_array(&colnum, 1); send_int_array(&m->rownum, 1); send_int_array(&m->nzcnt, 1); send_int_array(m->colnames, colnum); send_dbl_array(m->obj, colnum); send_int_array(m->matbeg, colnum + 1); send_char_array((char *)m->matind, m->nzcnt * sizeof(row_ind_type)); #endif return(USER_SUCCESS); }
int send_lp_data_u(sym_environment *env, int sender) { #if defined(COMPILE_IN_TM) && defined(COMPILE_IN_LP) int i; tm_prob *tm = env->tm; tm->par.max_active_nodes = env->par.tm_par.max_active_nodes; #ifdef _OPENMP omp_set_dynamic(FALSE); omp_set_num_threads(tm->par.max_active_nodes); #else tm->par.max_active_nodes = 1; #endif tm->lpp = (lp_prob **) malloc(tm->par.max_active_nodes * sizeof(lp_prob *)); #pragma omp parallel for for (i = 0; i < tm->par.max_active_nodes; i ++){ tm->lpp[i] = (lp_prob *) calloc(1, sizeof(lp_prob)); tm->lpp[i]->proc_index = i; tm->lpp[i]->par = env->par.lp_par; if ((tm->lpp[i]->has_ub = env->has_ub)){ tm->lpp[i]->ub = env->ub; }else{ env->ub = - (MAXDOUBLE / 2); } if (env->par.multi_criteria){ if ((tm->lpp[i]->has_mc_ub = env->has_mc_ub)){ tm->lpp[i]->mc_ub = env->mc_ub; tm->lpp[i]->obj[0] = env->obj[0]; tm->lpp[i]->obj[1] = env->obj[1]; }else{ env->mc_ub = - (MAXDOUBLE / 2); } tm->lpp[i]->utopia[0] = env->utopia[0]; tm->lpp[i]->utopia[1] = env->utopia[1]; } tm->lpp[i]->draw_graph = env->dg_tid; tm->lpp[i]->base = *(env->base); tm->lpp[i]->mip = env->mip; #ifdef USE_SYM_APPLICATION CALL_USER_FUNCTION( user_send_lp_data(env->user, &(tm->lpp[i]->user)) ); #endif } #else int s_bufid; s_bufid = init_send(DataInPlace); send_char_array((char *)(&env->par.lp_par), sizeof(lp_params)); send_char_array(&env->has_ub, 1); if (env->has_ub) send_dbl_array(&env->ub, 1); if (env->par.multi_crtieria){ send_char_array(&env->has_mc_ub, 1); if (env->has_mc_ub){ send_dbl_array(&env->mc_ub, 1); send_dbl_array(env->obj, 2); } send_dbl_array(env->utopia, 2); } send_int_array(&env->dg_tid, 1); send_int_array(&env->base->varnum, 1); if (env->base->varnum){ send_int_array(env->base->userind, env->base->varnum); } send_int_array(&env->base->cutnum, 1); if (env->mip){ MIPdesc *mip = env->mip; char has_desc = TRUE; char has_colnames = FALSE; send_char_array(&has_desc, 1); send_int_array(&(mip->m), 1); send_int_array(&(mip->n), 1); send_int_array(&(mip->nz), 1); send_char_array(&(mip->obj_sense), 1); send_dbl_array(&(mip->obj_offset), 1); send_int_array(mip->matbeg, mip->n); send_int_array(mip->matind, mip->nz); send_dbl_array(mip->matval, mip->nz); send_dbl_array(mip->obj, mip->n); if (env->par.multi_criteria){ send_dbl_array(mip->obj, mip->n); send_dbl_array(mip->obj2, mip->n); } send_dbl_array(mip->rhs, mip->m); send_char_array(mip->sense, mip->m); send_dbl_array(mip->rngval, mip->m); send_dbl_array(mip->ub, mip->n); send_dbl_array(mip->lb, mip->n); send_char_array(mip->is_int, mip->n); if (mip->colname){ int i; has_colnames = TRUE; send_char_array(&has_colnames, 1); for (i = 0; i < mip->n; i++){ send_char_array(mip->colname[i], 8); } }else{ send_char_array(&has_colnames, 1); } }else{ char has_desc = FALSE; send_char_array(&has_desc, 1); } #ifdef USE_SYM_APPLICATION CALL_USER_FUNCTION( user_send_lp_data(env->user, NULL) ); #endif send_msg(sender, LP_DATA); freebuf(s_bufid); #endif return(FUNCTION_TERMINATED_NORMALLY); }
int main(void) { int r_bufid = 0, s_bufid = 0; cg_prob *p; int num_cuts = 0; double elapsed; struct timeval tout = {15, 0}; p = (cg_prob *) calloc(1, sizeof(cg_prob)); cg_initialize(p, 0); /*------------------------------------------------------------------------*\ * The main loop -- executes continuously until the program exits \*------------------------------------------------------------------------*/ while (TRUE){ /* Wait until a message arrives */ do{ r_bufid = treceive_msg(ANYONE, ANYTHING, &tout); if (!r_bufid){ if (pstat(p->tree_manager) != PROCESS_OK){ printf("TM has died -- CG exiting\n\n"); exit(-401); } } }while (!r_bufid); if (cg_process_message(p, r_bufid) == USER_ERROR) p->msgtag = USER_ERROR; /* If there is still something in the queue, process it */ do{ r_bufid = nreceive_msg(ANYONE, ANYTHING); if (r_bufid > 0) if (cg_process_message(p, r_bufid) == USER_ERROR) p->msgtag = USER_ERROR; }while (r_bufid != 0); /*--------------------------------------------------------------------- * Now the message queue is empty. If the last message was NOT some * kind of LP_SOLUTION then we can't generate solutions now. * Otherwise, generate solutions! *---------------------------------------------------------------------*/ if (p->msgtag == LP_SOLUTION_NONZEROS || p->msgtag == LP_SOLUTION_USER || p->msgtag == LP_SOLUTION_FRACTIONS){ if (p->par.do_findcuts) if ((termcode = find_cuts_u(p, NULL, &num_cuts)) < 0) printf("Warning: User error detected in cut generator\n\n"); /*-- send signal back to the LP that the cut generator is done -----*/ s_bufid = init_send(DataInPlace); send_int_array(&num_cuts, 1); elapsed = used_time(&p->tt); send_dbl_array(&elapsed, 1); send_int_array(&p->cur_sol.xindex, 1); send_int_array(&p->cur_sol.xiter_num, 1); send_msg(p->cur_sol.lp, NO_MORE_CUTS); freebuf(s_bufid); FREE(p->cur_sol.xind); FREE(p->cur_sol.xval); } } return(0); }