void lpp_solve_net(lpp_t *lpp, const char *host, const char *solver) { char buf[1024]; int n, fd, ready; lpp_comm_t *comm; ir_timer_t *t_send, *t_recv; ERR_CHECK_RETURN_VOID(fd = connect_tcp(host, LPP_PORT), <, 0, ("could not connect to %s", host)); comm = lpp_comm_new(fd, LPP_BUFSIZE); /* Set the solver */ lpp_writel(comm, LPP_CMD_SOLVER); lpp_writes(comm, solver); lpp_flush(comm); t_send = ir_timer_new(); t_recv = ir_timer_new(); ir_timer_start(t_send); lpp_writel(comm, LPP_CMD_PROBLEM); lpp_serialize(comm, lpp, 1); lpp_serialize_values(comm, lpp, lpp_value_start); lpp_flush(comm); ir_timer_stop(t_send); lpp->send_time = ir_timer_elapsed_usec(t_send); ready = 0; while (! ready) { int cmd = lpp_readl(comm); switch(cmd) { case LPP_CMD_SOLUTION: ir_timer_push(t_recv); lpp_deserialize_stats(comm, lpp); lpp_deserialize_values(comm, lpp, lpp_value_solution); ir_timer_stop(t_recv); lpp->recv_time = ir_timer_elapsed_usec(t_recv); ready = 1; break; case LPP_CMD_INFO: lpp_readbuf(comm, buf, sizeof(buf)); buf[sizeof(buf) - 1] = '\0'; if(lpp->log != NULL) { fputs(buf, lpp->log); n = strlen(buf); if(buf[n - 1] != '\n') putc('\n', lpp->log); fflush(lpp->log); } break; case LPP_CMD_BAD: fprintf(stderr, "solver process died unexpectedly\n"); goto end; default: fprintf(stderr, "invalid command: %s(%d)\n", lpp_get_cmd_name(cmd), cmd); return; } } lpp_writel(comm, LPP_CMD_BYE); lpp_flush(comm); end: lpp_comm_free(comm); #ifdef _WIN32 closesocket(fd); #else close(fd); #endif }
static void apply_heuristic_reductions_co(pbqp_t *pbqp, deq_t *rpeo) { #if KAPS_TIMING /* create timers */ ir_timer_t *t_edge = ir_timer_new(); ir_timer_t *t_r1 = ir_timer_new(); ir_timer_t *t_r2 = ir_timer_new(); ir_timer_t *t_rn = ir_timer_new(); #endif for (;;) { if (edge_bucket_get_length(edge_bucket) > 0) { #if KAPS_TIMING ir_timer_start(t_edge); #endif apply_edge(pbqp); #if KAPS_TIMING ir_timer_stop(t_edge); #endif } else if (node_bucket_get_length(node_buckets[1]) > 0) { #if KAPS_TIMING ir_timer_start(t_r1); #endif apply_RI(pbqp); #if KAPS_TIMING ir_timer_stop(t_r1); #endif } else if (node_bucket_get_length(node_buckets[2]) > 0) { #if KAPS_TIMING ir_timer_start(t_r2); #endif apply_RII(pbqp); #if KAPS_TIMING ir_timer_stop(t_r2); #endif } else if (merged_node != NULL) { #if KAPS_TIMING ir_timer_start(t_rn); #endif apply_RN_co_without_selection(pbqp); #if KAPS_TIMING ir_timer_stop(t_rn); #endif } else if (node_bucket_get_length(node_buckets[3]) > 0) { #if KAPS_TIMING ir_timer_start(t_rn); #endif merge_into_RN_node(pbqp, rpeo); #if KAPS_TIMING ir_timer_stop(t_rn); #endif } else { #if KAPS_TIMING printf("PBQP RE reductions: %10.3lf msec\n", (double)ir_timer_elapsed_usec(t_edge) / 1000.0); printf("PBQP R1 reductions: %10.3lf msec\n", (double)ir_timer_elapsed_usec(t_r1) / 1000.0); printf("PBQP R2 reductions: %10.3lf msec\n", (double)ir_timer_elapsed_usec(t_r2) / 1000.0); printf("PBQP RN reductions: %10.3lf msec\n", (double)ir_timer_elapsed_usec(t_rn) / 1000.0); #endif return; } } }
void timer_stop(ir_timer_t *timer) { if (timers_inited) ir_timer_stop(timer); }