Hi all, thanks for your answers. I updated to version 4.63, but I keep getting errors such as "segmentation fault" or "glp_free: memory allocation error”.
I have a function, with a few parameters in input, which creates the MIP and solve it (attached the function which creates the MIP). This function is called by multiple threads with different parameters and they do not share any data. As soon as I call the function within a mutex lock/unlock everything works fine. I compiled the GLPK package with Clang/LLVM 4.9 which has support for TLS, so I think everything should be fine. Do I need to do something else to make GLPK thread safe? Thanks. Best, Simone
bool solve_mip(MyData *node1, struct MyData *node2) { glp_prob *mip; int ia[1+4], ja[1+4]; double ar[1+4], z, x1, x2, size1, size2; bool res = false; mip = glp_create_prob(); glp_set_prob_name(mip, "overlap"); glp_set_obj_dir(mip, GLP_MIN); glp_add_rows(mip, 1); glp_set_row_name(mip, 1, "c0"); long int diff = node1->start - node2->start; glp_set_row_bnds(mip, 1, GLP_FX, -1 * diff, -1 * diff); glp_add_cols(mip, 4); glp_set_col_name(mip, 1, "x1"); glp_set_col_bnds(mip, 1, GLP_DB, 0.0, node1->count); glp_set_obj_coef(mip, 1, node1->diff); glp_set_col_kind(mip, 1, GLP_IV); glp_set_col_name(mip, 2, "x2"); glp_set_col_bnds(mip, 2, GLP_DB, 0.0, node2->count); glp_set_obj_coef(mip, 2, node2->diff); glp_set_col_kind(mip, 2, GLP_IV); glp_set_col_name(mip, 3, "size1"); glp_set_col_bnds(mip, 3, GLP_DB, 0.0, (1 << (node1->size_type >> 4)) - 1); glp_set_col_kind(mip, 3, GLP_IV); glp_set_col_name(mip, 4, "size2"); glp_set_col_bnds(mip, 4, GLP_DB, 0.0, (1 << (node2->size_type >> 4)) - 1); glp_set_col_kind(mip, 4, GLP_IV); ia[1] = 1, ja[1] = 1, ar[1] = node1->diff; ia[2] = 1, ja[2] = 2, ar[2] = node2->diff; ar[2] *= -1; ia[3] = 1, ja[3] = 3, ar[3] = 1.0; ia[4] = 1, ja[4] = 4, ar[4] = -1.0; glp_load_matrix(mip, 4, ia, ja, ar); std::string filename = "ilp_problem" + std::to_string(rand()) + ".lp"; glp_iocp parm; glp_init_iocp(&parm); parm.presolve = GLP_ON; glp_term_out(GLP_OFF); glp_intopt(mip, &parm); int ret = glp_mip_status(mip); if(ret != GLP_NOFEAS) res = true; glp_delete_prob(mip); glp_free_env(); return res; }
> On Aug 25, 2017, at 01:13, Andrew Makhorin <m...@gnu.org> wrote: > > >> In the GLPK documentation, paragraph "2.1.3 Thread Safety" states: >> >> >> "The standard version of GLPK API is not thread safe and therefore >> should not be used in multi-threaded programs.” > > The *standard* (i.e. ANSI C89) version is not thread safe. However, > starting from 4.61 (released on Jan 2017) glpk can be used in > multi-threaded programs on some platforms (including GNU/Linux and MS > Windows); for more details please see: > https://lists.gnu.org/archive/html/help-glpk/2017-01/msg00111.html . > (It's better to use the most recent version, which is 4.63.)
_______________________________________________ Help-glpk mailing list Help-glpk@gnu.org https://lists.gnu.org/mailman/listinfo/help-glpk