lp_programs.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 - 2013 INRIA
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. /*
  17. * GNU Linear Programming Kit backend
  18. */
  19. #include "sc_hypervisor_policy.h"
  20. #include "sc_hypervisor_lp.h"
  21. #ifdef STARPU_HAVE_GLPK_H
  22. double sc_hypervisor_lp_simulate_distrib_tasks(int ns, int nw, int nt, double w_in_s[ns][nw], double tasks[nw][nt],
  23. double times[nw][nt], unsigned is_integer, double tmax, unsigned *in_sched_ctxs,
  24. struct sc_hypervisor_policy_task_pool *tmp_task_pools)
  25. {
  26. struct sc_hypervisor_policy_task_pool * tp;
  27. int t, w, s;
  28. glp_prob *lp;
  29. lp = glp_create_prob();
  30. glp_set_prob_name(lp, "StarPU theoretical bound");
  31. glp_set_obj_dir(lp, GLP_MAX);
  32. glp_set_obj_name(lp, "total execution time");
  33. {
  34. int ne = nt * nw /* worker execution time */
  35. + nw * ns
  36. + nw * (nt + ns)
  37. + 1; /* glp dumbness */
  38. int n = 1;
  39. int ia[ne], ja[ne];
  40. double ar[ne];
  41. /* Variables: number of tasks i assigned to worker j, and tmax */
  42. glp_add_cols(lp, nw*nt+ns*nw);
  43. #define colnum(w, t) ((t)*nw+(w)+1)
  44. for(s = 0; s < ns; s++)
  45. for(w = 0; w < nw; w++)
  46. glp_set_obj_coef(lp, nw*nt+s*nw+w+1, 1.);
  47. for (w = 0; w < nw; w++)
  48. for (t = 0; t < nt; t++)
  49. {
  50. char name[32];
  51. snprintf(name, sizeof(name), "w%dt%dn", w, t);
  52. glp_set_col_name(lp, colnum(w, t), name);
  53. /* if (integer) */
  54. /* { */
  55. /* glp_set_col_kind(lp, colnum(w, t), GLP_IV); */
  56. /* glp_set_col_bnds(lp, colnum(w, t), GLP_LO, 0, 0); */
  57. /* } */
  58. /* else */
  59. glp_set_col_bnds(lp, colnum(w, t), GLP_LO, 0.0, 0.0);
  60. }
  61. for(s = 0; s < ns; s++)
  62. for(w = 0; w < nw; w++)
  63. {
  64. char name[32];
  65. snprintf(name, sizeof(name), "w%ds%dn", w, s);
  66. glp_set_col_name(lp, nw*nt+s*nw+w+1, name);
  67. if (is_integer)
  68. {
  69. glp_set_col_kind(lp, nw*nt+s*nw+w+1, GLP_IV);
  70. glp_set_col_bnds(lp, nw*nt+s*nw+w+1, GLP_DB, 0, 1);
  71. }
  72. else
  73. glp_set_col_bnds(lp, nw*nt+s*nw+w+1, GLP_DB, 0.0, 1.0);
  74. }
  75. unsigned *sched_ctxs = in_sched_ctxs == NULL ? sc_hypervisor_get_sched_ctxs() : in_sched_ctxs;
  76. int curr_row_idx = 0;
  77. /* Total worker execution time */
  78. glp_add_rows(lp, nw*ns);
  79. for (t = 0; t < nt; t++)
  80. {
  81. int someone = 0;
  82. for (w = 0; w < nw; w++)
  83. if (!isnan(times[w][t]))
  84. someone = 1;
  85. if (!someone)
  86. {
  87. /* This task does not have any performance model at all, abort */
  88. printf("NO PERF MODELS\n");
  89. glp_delete_prob(lp);
  90. return 0.0;
  91. }
  92. }
  93. /*sum(t[t][w]*n[t][w]) < x[s][w]*tmax */
  94. for(s = 0; s < ns; s++)
  95. {
  96. for (w = 0; w < nw; w++)
  97. {
  98. char name[32], title[64];
  99. starpu_worker_get_name(w, name, sizeof(name));
  100. snprintf(title, sizeof(title), "worker %s", name);
  101. glp_set_row_name(lp, curr_row_idx+s*nw+w+1, title);
  102. for (t = 0, tp = tmp_task_pools; tp; t++, tp = tp->next)
  103. {
  104. if(tp->sched_ctx_id == sched_ctxs[s])
  105. {
  106. ia[n] = curr_row_idx+s*nw+w+1;
  107. ja[n] = colnum(w, t);
  108. if (isnan(times[w][t]))
  109. ar[n] = 1000000000.;
  110. else
  111. ar[n] = times[w][t];
  112. n++;
  113. }
  114. }
  115. /* x[s][w] = 1 | 0 */
  116. ia[n] = curr_row_idx+s*nw+w+1;
  117. ja[n] = nw*nt+s*nw+w+1;
  118. ar[n] = (-1) * tmax;
  119. n++;
  120. glp_set_row_bnds(lp, curr_row_idx+s*nw+w+1, GLP_UP, 0.0, 0.0);
  121. }
  122. }
  123. curr_row_idx += nw*ns;
  124. /* Total task completion */
  125. glp_add_rows(lp, nt);
  126. for (t = 0, tp = tmp_task_pools; tp; t++, tp = tp->next)
  127. {
  128. char name[32], title[64];
  129. starpu_worker_get_name(w, name, sizeof(name));
  130. snprintf(title, sizeof(title), "task %s key %x", tp->cl->name, (unsigned) tp->footprint);
  131. glp_set_row_name(lp, curr_row_idx+t+1, title);
  132. for (w = 0; w < nw; w++)
  133. {
  134. ia[n] = curr_row_idx+t+1;
  135. ja[n] = colnum(w, t);
  136. ar[n] = 1;
  137. n++;
  138. }
  139. glp_set_row_bnds(lp, curr_row_idx+t+1, GLP_FX, tp->n, tp->n);
  140. }
  141. curr_row_idx += nt;
  142. /* sum(x[s][i]) = 1 */
  143. glp_add_rows(lp, nw);
  144. for (w = 0; w < nw; w++)
  145. {
  146. char name[32], title[64];
  147. starpu_worker_get_name(w, name, sizeof(name));
  148. snprintf(title, sizeof(title), "w%x", w);
  149. glp_set_row_name(lp, curr_row_idx+w+1, title);
  150. for(s = 0; s < ns; s++)
  151. {
  152. ia[n] = curr_row_idx+w+1;
  153. ja[n] = nw*nt+s*nw+w+1;
  154. ar[n] = 1;
  155. n++;
  156. }
  157. if(is_integer)
  158. glp_set_row_bnds(lp, curr_row_idx+w+1, GLP_FX, 1, 1);
  159. else
  160. glp_set_row_bnds(lp, curr_row_idx+w+1, GLP_FX, 1.0, 1.0);
  161. }
  162. if(n != ne)
  163. printf("ns= %d nw = %d nt = %d n = %d ne = %d\n", ns, nw, nt, n, ne);
  164. STARPU_ASSERT(n == ne);
  165. glp_load_matrix(lp, ne-1, ia, ja, ar);
  166. }
  167. glp_smcp parm;
  168. glp_init_smcp(&parm);
  169. parm.msg_lev = GLP_MSG_OFF;
  170. int ret = glp_simplex(lp, &parm);
  171. /* char str[50]; */
  172. /* sprintf(str, "outpu_lp_%g", tmax); */
  173. /* glp_print_sol(lp, str); */
  174. if (ret)
  175. {
  176. printf("error in simplex\n");
  177. glp_delete_prob(lp);
  178. lp = NULL;
  179. return 0.0;
  180. }
  181. int stat = glp_get_prim_stat(lp);
  182. /* if we don't have a solution return */
  183. if(stat == GLP_NOFEAS)
  184. {
  185. glp_delete_prob(lp);
  186. // printf("no_sol in tmax = %lf\n", tmax);
  187. lp = NULL;
  188. return 0.0;
  189. }
  190. if (is_integer)
  191. {
  192. glp_iocp iocp;
  193. glp_init_iocp(&iocp);
  194. iocp.msg_lev = GLP_MSG_OFF;
  195. glp_intopt(lp, &iocp);
  196. int stat = glp_mip_status(lp);
  197. /* if we don't have a solution return */
  198. if(stat == GLP_NOFEAS)
  199. {
  200. // printf("no int sol in tmax = %lf\n", tmax);
  201. glp_delete_prob(lp);
  202. lp = NULL;
  203. return 0.0;
  204. }
  205. }
  206. double res = glp_get_obj_val(lp);
  207. for (w = 0; w < nw; w++)
  208. for (t = 0; t < nt; t++)
  209. /* if (integer) */
  210. /* tasks[w][t] = (double)glp_mip_col_val(lp, colnum(w, t)); */
  211. /* else */
  212. tasks[w][t] = glp_get_col_prim(lp, colnum(w, t));
  213. // printf("for tmax %lf\n", tmax);
  214. for(s = 0; s < ns; s++)
  215. for(w = 0; w < nw; w++)
  216. {
  217. if (is_integer)
  218. w_in_s[s][w] = (double)glp_mip_col_val(lp, nw*nt+s*nw+w+1);
  219. else
  220. w_in_s[s][w] = glp_get_col_prim(lp, nw*nt+s*nw+w+1);
  221. // printf("w %d in ctx %d = %lf\n", w, s, w_in_s[s][w]);
  222. }
  223. // printf("\n");
  224. glp_delete_prob(lp);
  225. return res;
  226. }
  227. double sc_hypervisor_lp_simulate_distrib_flops(int ns, int nw, double v[ns][nw], double flops[ns], double res[ns][nw], int total_nw[nw])
  228. {
  229. int integer = 1;
  230. int s, w;
  231. glp_prob *lp;
  232. int ne =
  233. (ns*nw+1)*(ns+nw)
  234. + 1; /* glp dumbness */
  235. int n = 1;
  236. int ia[ne], ja[ne];
  237. double ar[ne];
  238. lp = glp_create_prob();
  239. glp_set_prob_name(lp, "sample");
  240. glp_set_obj_dir(lp, GLP_MAX);
  241. glp_set_obj_name(lp, "max speed");
  242. /* we add nw*ns columns one for each type of worker in each context
  243. and another column corresponding to the 1/tmax bound (bc 1/tmax is a variable too)*/
  244. glp_add_cols(lp, nw*ns+1);
  245. for(s = 0; s < ns; s++)
  246. {
  247. for(w = 0; w < nw; w++)
  248. {
  249. char name[32];
  250. snprintf(name, sizeof(name), "worker%dctx%d", w, s);
  251. glp_set_col_name(lp, n, name);
  252. if (integer)
  253. {
  254. glp_set_col_kind(lp, n, GLP_IV);
  255. glp_set_col_bnds(lp, n, GLP_LO, 0, 0);
  256. }
  257. else
  258. glp_set_col_bnds(lp, n, GLP_LO, 0.0, 0.0);
  259. n++;
  260. }
  261. }
  262. /*1/tmax should belong to the interval [0.0;1.0]*/
  263. glp_set_col_name(lp, n, "vmax");
  264. // glp_set_col_bnds(lp, n, GLP_DB, 0.0, 1.0);
  265. glp_set_col_bnds(lp, n, GLP_LO, 0.0, 0.0);
  266. /* Z = 1/tmax -> 1/tmax structural variable, nCPUs & nGPUs in ctx are auxiliar variables */
  267. glp_set_obj_coef(lp, n, 1.0);
  268. n = 1;
  269. /* one row corresponds to one ctx*/
  270. glp_add_rows(lp, ns);
  271. for(s = 0; s < ns; s++)
  272. {
  273. char name[32];
  274. snprintf(name, sizeof(name), "ctx%d", s);
  275. glp_set_row_name(lp, s+1, name);
  276. glp_set_row_bnds(lp, s+1, GLP_LO, 0., 0.);
  277. for(w = 0; w < nw; w++)
  278. {
  279. int s2;
  280. for(s2 = 0; s2 < ns; s2++)
  281. {
  282. if(s2 == s)
  283. {
  284. ia[n] = s+1;
  285. ja[n] = w + nw*s2 + 1;
  286. ar[n] = v[s][w];
  287. // printf("ia[%d]=%d ja[%d]=%d ar[%d]=%lf\n", n, ia[n], n, ja[n], n, ar[n]);
  288. }
  289. else
  290. {
  291. ia[n] = s+1;
  292. ja[n] = w + nw*s2 + 1;
  293. ar[n] = 0.0;
  294. // printf("ia[%d]=%d ja[%d]=%d ar[%d]=%lf\n", n, ia[n], n, ja[n], n, ar[n]);
  295. }
  296. n++;
  297. }
  298. }
  299. /* 1/tmax */
  300. ia[n] = s+1;
  301. ja[n] = ns*nw+1;
  302. ar[n] = (-1) * flops[s];
  303. // printf("ia[%d]=%d ja[%d]=%d ar[%d]=%lf\n", n, ia[n], n, ja[n], n, ar[n]);
  304. n++;
  305. }
  306. /*we add another linear constraint : sum(all cpus) = 9 and sum(all gpus) = 3 */
  307. glp_add_rows(lp, nw);
  308. for(w = 0; w < nw; w++)
  309. {
  310. char name[32];
  311. snprintf(name, sizeof(name), "w%d", w);
  312. glp_set_row_name(lp, ns+w+1, name);
  313. for(s = 0; s < ns; s++)
  314. {
  315. int w2;
  316. for(w2 = 0; w2 < nw; w2++)
  317. {
  318. if(w2 == w)
  319. {
  320. ia[n] = ns+w+1;
  321. ja[n] = w2+s*nw + 1;
  322. ar[n] = 1.0;
  323. // printf("ia[%d]=%d ja[%d]=%d ar[%d]=%lf\n", n, ia[n], n, ja[n], n, ar[n]);
  324. }
  325. else
  326. {
  327. ia[n] = ns+w+1;
  328. ja[n] = w2+s*nw + 1;
  329. ar[n] = 0.0;
  330. // printf("ia[%d]=%d ja[%d]=%d ar[%d]=%lf\n", n, ia[n], n, ja[n], n, ar[n]);
  331. }
  332. n++;
  333. }
  334. }
  335. /* 1/tmax */
  336. ia[n] = ns+w+1;
  337. ja[n] = ns*nw+1;
  338. ar[n] = 0.0;
  339. // printf("ia[%d]=%d ja[%d]=%d ar[%d]=%lf\n", n, ia[n], n, ja[n], n, ar[n]);
  340. n++;
  341. /*sum(all gpus) = 3*/
  342. if(w == 0)
  343. glp_set_row_bnds(lp, ns+w+1, GLP_FX, total_nw[0], total_nw[0]);
  344. /*sum(all cpus) = 9*/
  345. if(w == 1)
  346. glp_set_row_bnds(lp, ns+w+1, GLP_FX, total_nw[1], total_nw[1]);
  347. }
  348. STARPU_ASSERT(n == ne);
  349. glp_load_matrix(lp, ne-1, ia, ja, ar);
  350. glp_smcp parm;
  351. glp_init_smcp(&parm);
  352. parm.msg_lev = GLP_MSG_OFF;
  353. int ret = glp_simplex(lp, &parm);
  354. if (ret)
  355. {
  356. printf("error in simplex\n");
  357. glp_delete_prob(lp);
  358. lp = NULL;
  359. return 0.0;
  360. }
  361. int stat = glp_get_prim_stat(lp);
  362. /* if we don't have a solution return */
  363. if(stat == GLP_NOFEAS)
  364. {
  365. glp_delete_prob(lp);
  366. // printf("no_sol in tmax = %lf\n", tmax);
  367. lp = NULL;
  368. return 0.0;
  369. }
  370. if (integer)
  371. {
  372. glp_iocp iocp;
  373. glp_init_iocp(&iocp);
  374. iocp.msg_lev = GLP_MSG_OFF;
  375. glp_intopt(lp, &iocp);
  376. int stat = glp_mip_status(lp);
  377. /* if we don't have a solution return */
  378. if(stat == GLP_NOFEAS)
  379. {
  380. // printf("no int sol in tmax = %lf\n", tmax);
  381. glp_delete_prob(lp);
  382. lp = NULL;
  383. return 0.0;
  384. }
  385. }
  386. double vmax = glp_get_obj_val(lp);
  387. // printf("vmax = %lf \n", vmax);
  388. n = 1;
  389. for(s = 0; s < ns; s++)
  390. {
  391. for(w = 0; w < nw; w++)
  392. {
  393. if (integer)
  394. res[s][w] = (double)glp_mip_col_val(lp, n);
  395. else
  396. res[s][w] = glp_get_col_prim(lp, n);
  397. // printf("%d/%d: res %lf flops = %lf v = %lf\n", w,s, res[s][w], flops[s], v[s][w]);
  398. n++;
  399. }
  400. }
  401. glp_delete_prob(lp);
  402. return vmax;
  403. }
  404. double sc_hypervisor_lp_simulate_distrib_flops_on_sample(int ns, int nw, double final_w_in_s[ns][nw], unsigned is_integer, double tmax,
  405. double **speed, double flops[ns], double **final_flops_on_w)
  406. {
  407. double w_in_s[ns][nw];
  408. double flops_on_w[ns][nw];
  409. int w, s;
  410. glp_prob *lp;
  411. // printf("try with tmax %lf\n", tmax);
  412. lp = glp_create_prob();
  413. glp_set_prob_name(lp, "StarPU theoretical bound");
  414. glp_set_obj_dir(lp, GLP_MAX);
  415. glp_set_obj_name(lp, "total execution time");
  416. {
  417. int ne = 5 * ns * nw /* worker execution time */
  418. + 1; /* glp dumbness */
  419. int n = 1;
  420. int ia[ne], ja[ne];
  421. double ar[ne];
  422. /* Variables: number of flops assigned to worker w in context s, and
  423. the acknwoledgment that the worker w belongs to the context s */
  424. glp_add_cols(lp, 2*nw*ns);
  425. #define colnum_sample(w, s) ((s)*nw+(w)+1)
  426. for(s = 0; s < ns; s++)
  427. for(w = 0; w < nw; w++)
  428. glp_set_obj_coef(lp, nw*ns+colnum_sample(w,s), 1.);
  429. for(s = 0; s < ns; s++)
  430. for(w = 0; w < nw; w++)
  431. {
  432. char name[32];
  433. snprintf(name, sizeof(name), "flopsw%ds%dn", w, s);
  434. glp_set_col_name(lp, colnum_sample(w,s), name);
  435. glp_set_col_bnds(lp, colnum_sample(w,s), GLP_LO, 0., 0.);
  436. snprintf(name, sizeof(name), "w%ds%dn", w, s);
  437. glp_set_col_name(lp, nw*ns+colnum_sample(w,s), name);
  438. if (is_integer)
  439. {
  440. glp_set_col_kind(lp, nw*ns+colnum_sample(w, s), GLP_IV);
  441. glp_set_col_bnds(lp, nw*ns+colnum_sample(w,s), GLP_DB, 0, 1);
  442. }
  443. else
  444. glp_set_col_bnds(lp, nw*ns+colnum_sample(w,s), GLP_DB, 0.0, 1.0);
  445. }
  446. int curr_row_idx = 0;
  447. /* Total worker execution time */
  448. glp_add_rows(lp, nw*ns);
  449. /*nflops[s][w]/v[s][w] < x[s][w]*tmax */
  450. for(s = 0; s < ns; s++)
  451. {
  452. for (w = 0; w < nw; w++)
  453. {
  454. char name[32], title[64];
  455. starpu_worker_get_name(w, name, sizeof(name));
  456. snprintf(title, sizeof(title), "worker %s", name);
  457. glp_set_row_name(lp, curr_row_idx+s*nw+w+1, title);
  458. /* nflosp[s][w] */
  459. ia[n] = curr_row_idx+s*nw+w+1;
  460. ja[n] = colnum_sample(w, s);
  461. ar[n] = 1 / speed[s][w];
  462. n++;
  463. /* x[s][w] = 1 | 0 */
  464. ia[n] = curr_row_idx+s*nw+w+1;
  465. ja[n] = nw*ns+colnum_sample(w,s);
  466. ar[n] = (-1) * tmax;
  467. n++;
  468. glp_set_row_bnds(lp, curr_row_idx+s*nw+w+1, GLP_UP, 0.0, 0.0);
  469. }
  470. }
  471. curr_row_idx += nw*ns;
  472. /* sum(flops[s][w]) = flops[s] */
  473. glp_add_rows(lp, ns);
  474. for (s = 0; s < ns; s++)
  475. {
  476. char name[32], title[64];
  477. starpu_worker_get_name(w, name, sizeof(name));
  478. snprintf(title, sizeof(title), "flops %lf ctx%d", flops[s], s);
  479. glp_set_row_name(lp, curr_row_idx+s+1, title);
  480. for (w = 0; w < nw; w++)
  481. {
  482. ia[n] = curr_row_idx+s+1;
  483. ja[n] = colnum_sample(w, s);
  484. ar[n] = 1;
  485. n++;
  486. }
  487. glp_set_row_bnds(lp, curr_row_idx+s+1, GLP_FX, flops[s], flops[s]);
  488. }
  489. curr_row_idx += ns;
  490. /* sum(x[s][w]) = 1 */
  491. glp_add_rows(lp, nw);
  492. for (w = 0; w < nw; w++)
  493. {
  494. char name[32], title[64];
  495. starpu_worker_get_name(w, name, sizeof(name));
  496. snprintf(title, sizeof(title), "w%x", w);
  497. glp_set_row_name(lp, curr_row_idx+w+1, title);
  498. for(s = 0; s < ns; s++)
  499. {
  500. ia[n] = curr_row_idx+w+1;
  501. ja[n] = nw*ns+colnum_sample(w,s);
  502. ar[n] = 1;
  503. n++;
  504. }
  505. if(is_integer)
  506. glp_set_row_bnds(lp, curr_row_idx+w+1, GLP_FX, 1, 1);
  507. else
  508. glp_set_row_bnds(lp, curr_row_idx+w+1, GLP_FX, 1.0, 1.0);
  509. }
  510. curr_row_idx += nw;
  511. /* sum(nflops[s][w]) > 0*/
  512. glp_add_rows(lp, nw);
  513. for (w = 0; w < nw; w++)
  514. {
  515. char name[32], title[64];
  516. starpu_worker_get_name(w, name, sizeof(name));
  517. snprintf(title, sizeof(title), "flopsw%x", w);
  518. glp_set_row_name(lp, curr_row_idx+w+1, title);
  519. for(s = 0; s < ns; s++)
  520. {
  521. ia[n] = curr_row_idx+w+1;
  522. ja[n] = colnum_sample(w,s);
  523. ar[n] = 1;
  524. n++;
  525. }
  526. glp_set_row_bnds(lp, curr_row_idx+w+1, GLP_LO, 0.1, 0.);
  527. }
  528. if(n != ne)
  529. printf("ns= %d nw = %d n = %d ne = %d\n", ns, nw, n, ne);
  530. STARPU_ASSERT(n == ne);
  531. glp_load_matrix(lp, ne-1, ia, ja, ar);
  532. }
  533. glp_smcp parm;
  534. glp_init_smcp(&parm);
  535. parm.msg_lev = GLP_MSG_OFF;
  536. int ret = glp_simplex(lp, &parm);
  537. if (ret)
  538. {
  539. glp_delete_prob(lp);
  540. lp = NULL;
  541. return 0.0;
  542. }
  543. if (is_integer)
  544. {
  545. glp_iocp iocp;
  546. glp_init_iocp(&iocp);
  547. iocp.msg_lev = GLP_MSG_OFF;
  548. glp_intopt(lp, &iocp);
  549. int stat = glp_mip_status(lp);
  550. /* if we don't have a solution return */
  551. if(stat == GLP_NOFEAS)
  552. {
  553. glp_delete_prob(lp);
  554. lp = NULL;
  555. return 0.0;
  556. }
  557. }
  558. int stat = glp_get_prim_stat(lp);
  559. /* if we don't have a solution return */
  560. if(stat == GLP_NOFEAS)
  561. {
  562. glp_delete_prob(lp);
  563. lp = NULL;
  564. return 0.0;
  565. }
  566. double res = glp_get_obj_val(lp);
  567. for(s = 0; s < ns; s++)
  568. for(w = 0; w < nw; w++)
  569. {
  570. flops_on_w[s][w] = glp_get_col_prim(lp, colnum_sample(w, s));
  571. if (is_integer)
  572. w_in_s[s][w] = (double)glp_mip_col_val(lp, nw*ns+colnum_sample(w, s));
  573. else
  574. w_in_s[s][w] = glp_get_col_prim(lp, nw*ns+colnum_sample(w,s));
  575. // printf("w_in_s[s%d][w%d] = %lf flops[s%d][w%d] = %lf \n", s, w, w_in_s[s][w], s, w, flops_on_w[s][w]);
  576. }
  577. glp_delete_prob(lp);
  578. for(s = 0; s < ns; s++)
  579. for(w = 0; w < nw; w++)
  580. {
  581. final_w_in_s[s][w] = w_in_s[s][w];
  582. final_flops_on_w[s][w] = flops_on_w[s][w];
  583. }
  584. return res;
  585. }
  586. #endif // STARPU_HAVE_GLPK_H