/* steal jobs from other workers */ jobinfo* steal() { int i,w,b; int len,tid,tag; jobinfo *j; w = random() % nw; for (;;) { if (wtid[w] != stid) { pvm_initsend(0); pvm_send(wtid[w],TAG_REQUEST); for (;;) { b = pvm_recv(-1,-1); pvm_bufinfo(b,&len,&tag,&tid); if (tag == TAG_JOB || tag == TAG_NO_JOB) break; else if (tag == TAG_REQUEST) { pvm_initsend(0); pvm_send(tid,TAG_NO_JOB); } else p_handle(b); } if (tag == TAG_JOB) break; } if (++w == nw) w = 0; } j = malloc(sizeof(jobinfo)); upkjobinfo_active(j); ha_lookup(ha,&j->s.da,&j->s.p); return j; }
/* add self to worker list */ void hello() { int i,b,n; pvmtaskinfo *ta; pvm_tasks(0,&n,&ta); for (i=0;i<n;i++) if (!strcmp(ta[i].ti_a_out,"kalah")) { pvm_initsend(0); pvm_pkstr(host); pvm_send(ta[i].ti_tid,TAG_HELLO); break; } b = pvm_recv(-1,TAG_WORKERS); if (b < 0) die("Failed to receive worker list\n"); p_handle(b); }
void RectKnotHolderEntityXY::knot_set(Geom::Point const &p, Geom::Point const &origin, guint state) { SPRect *rect = SP_RECT(item); // opposite corner (unmoved) gdouble opposite_x = (rect->x.computed + rect->width.computed); gdouble opposite_y = (rect->y.computed + rect->height.computed); // original width/height when drag started gdouble w_orig = opposite_x - origin[Geom::X]; gdouble h_orig = opposite_y - origin[Geom::Y]; Geom::Point s = p; Geom::Point p_handle(rect->x.computed, rect->y.computed); // mouse displacement since drag started gdouble minx = p[Geom::X] - origin[Geom::X]; gdouble miny = p[Geom::Y] - origin[Geom::Y]; if (state & GDK_CONTROL_MASK) { //original ratio gdouble ratio = (w_orig / h_orig); if (fabs(minx) > fabs(miny)) { // snap to horizontal or diagonal if (minx != 0 && fabs(miny/minx) > 0.5 * 1/ratio && (SGN(minx) == SGN(miny))) { // closer to the diagonal and in same-sign quarters, change both using ratio s = snap_knot_position_constrained(p, Inkscape::Snapper::SnapConstraint(p_handle, Geom::Point(-ratio, -1)), state); minx = s[Geom::X] - origin[Geom::X]; miny = s[Geom::Y] - origin[Geom::Y]; rect->y.computed = MIN(origin[Geom::Y] + minx / ratio, opposite_y); rect->height.computed = MAX(h_orig - minx / ratio, 0); } else { // closer to the horizontal, change only width, height is h_orig s = snap_knot_position_constrained(p, Inkscape::Snapper::SnapConstraint(p_handle, Geom::Point(-1, 0)), state); minx = s[Geom::X] - origin[Geom::X]; miny = s[Geom::Y] - origin[Geom::Y]; rect->y.computed = MIN(origin[Geom::Y], opposite_y); rect->height.computed = MAX(h_orig, 0); } rect->x.computed = MIN(s[Geom::X], opposite_x); rect->width.computed = MAX(w_orig - minx, 0); } else { // snap to vertical or diagonal if (miny != 0 && fabs(minx/miny) > 0.5 *ratio && (SGN(minx) == SGN(miny))) { // closer to the diagonal and in same-sign quarters, change both using ratio s = snap_knot_position_constrained(p, Inkscape::Snapper::SnapConstraint(p_handle, Geom::Point(-ratio, -1)), state); minx = s[Geom::X] - origin[Geom::X]; miny = s[Geom::Y] - origin[Geom::Y]; rect->x.computed = MIN(origin[Geom::X] + miny * ratio, opposite_x); rect->width.computed = MAX(w_orig - miny * ratio, 0); } else { // closer to the vertical, change only height, width is w_orig s = snap_knot_position_constrained(p, Inkscape::Snapper::SnapConstraint(p_handle, Geom::Point(0, -1)), state); minx = s[Geom::X] - origin[Geom::X]; miny = s[Geom::Y] - origin[Geom::Y]; rect->x.computed = MIN(origin[Geom::X], opposite_x); rect->width.computed = MAX(w_orig, 0); } rect->y.computed = MIN(s[Geom::Y], opposite_y); rect->height.computed = MAX(h_orig - miny, 0); } rect->width._set = rect->height._set = rect->x._set = rect->y._set = true; } else { // move freely s = snap_knot_position(p, state); minx = s[Geom::X] - origin[Geom::X]; miny = s[Geom::Y] - origin[Geom::Y]; rect->x.computed = MIN(s[Geom::X], opposite_x); rect->width.computed = MAX(w_orig - minx, 0); rect->y.computed = MIN(s[Geom::Y], opposite_y); rect->height.computed = MAX(h_orig - miny, 0); rect->width._set = rect->height._set = rect->x._set = rect->y._set = true; } sp_rect_clamp_radii(rect); update_knot(); (static_cast<SPObject *>(rect))->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); }