/** * Record debugging configuration. */ void dbmw_set_debugging(dbmw_t *dw, const dbg_config_t *dbg) { dbmw_check(dw); dw->dbg = dbg; if (dbg_ds_debugging(dw->dbg, 1, DBG_DSF_DEBUGGING)) { dbg_ds_log(dw->dbg, dw, "%s: attached with %s back-end " "(max cached = %zu, key=%zu bytes, value=%zu bytes, " "%zu max serialized)", G_STRFUNC, dbmw_map_type(dw) == DBMAP_SDBM ? "sdbm" : "map", dw->max_cached, dw->key_size, dw->value_size, dw->value_data_size); } /* * Patch in place for the DBMAP. */ WFREE_TYPE_NULL(dw->dbmap_dbg); dw->dbmap_dbg = WCOPY(dbg); dw->dbmap_dbg->o2str = NULL; dw->dbmap_dbg->type = "DBMAP"; dbmap_set_debugging(dw->dm, dw->dbmap_dbg); }
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ char ros_PrepareMatrix ( /* Inout argument: (step size is decreased when LU fails) */ double* H, /* Input arguments: */ int Direction, double gam, double Jac0[], /* Output arguments: */ double Ghimj[], int Pivot[] ) /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Prepares the LHS matrix for stage calculations 1. Construct Ghimj = 1/(H*ham) - Jac0 "(Gamma H) Inverse Minus Jacobian" 2. Repeat LU decomposition of Ghimj until successful. -half the step size if LU decomposition fails and retry -exit after 5 consecutive fails Return value: Singular (true=1=failed_LU or false=0=successful_LU) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ { /*~~~> Local variables */ int i, ising, Nconsecutive; double ghinv; Nconsecutive = 0; while (1) { /* while Singular */ /*~~~> Construct Ghimj = 1/(H*ham) - Jac0 */ WCOPY(920,Jac0,1,Ghimj,1); WSCAL(920,(-ONE),Ghimj,1); ghinv = ONE/(Direction*(*H)*gam); for (i=0; i<74; i++) { Ghimj[LU_DIAG[i]] = Ghimj[LU_DIAG[i]]+ghinv; } /* for i */ /*~~~> Compute LU decomposition */ DecompTemplate( Ghimj, Pivot, &ising ); if (ising == 0) { /*~~~> if successful done */ return 0; /* Singular = false */ } else { /* ising .ne. 0 */ /*~~~> if unsuccessful half the step size; if 5 consecutive fails return */ Nsng++; Nconsecutive++; printf("\nWarning: LU Decomposition returned ising = %d\n",ising); if (Nconsecutive <= 5) { /* Less than 5 consecutive failed LUs */ *H = (*H)*HALF; } else { /* More than 5 consecutive failed LUs */ return 1; /* Singular = true */ } /* end if Nconsecutive */ } /* end if ising */ } /* while Singular */ } /* ros_PrepareMatrix */
/** * Duplicate (create a copy of) a vector of Gnutella hosts. */ gnet_host_vec_t * gnet_host_vec_copy(const gnet_host_vec_t *vec) { gnet_host_vec_t *vec_copy; g_return_val_if_fail(vec, NULL); g_return_val_if_fail(vec->n_ipv4 + vec->n_ipv6 > 0, NULL); vec_copy = WCOPY(vec); if (vec->n_ipv4 > 0) vec_copy->hvec_v4 = WCOPY_ARRAY(vec->hvec_v4, vec->n_ipv4); if (vec->n_ipv6 > 0) vec_copy->hvec_v6 = WCOPY_ARRAY(vec->hvec_v6, vec->n_ipv6); return vec_copy; }
static pslist_t * resolve_hostname(const char *host, enum net_type net) #ifdef HAS_GETADDRINFO { static const struct addrinfo zero_hints; struct addrinfo hints, *ai, *ai0 = NULL; hset_t *hs; pslist_t *sl_addr; int error; g_assert(host); hints = zero_hints; hints.ai_family = net_type_to_pf(net); error = getaddrinfo(host, NULL, &hints, &ai0); if (error) { g_message("getaddrinfo() failed for \"%s\": %s", host, gai_strerror(error)); return NULL; } sl_addr = NULL; hs = hset_create_any(host_addr_hash_func, NULL, host_addr_eq_func); for (ai = ai0; ai; ai = ai->ai_next) { host_addr_t addr; if (!ai->ai_addr) continue; addr = addrinfo_to_addr(ai); if (is_host_addr(addr) && !hset_contains(hs, &addr)) { host_addr_t *addr_copy; addr_copy = WCOPY(&addr); sl_addr = pslist_prepend(sl_addr, addr_copy); hset_insert(hs, addr_copy); } } hset_free_null(&hs); if (ai0) freeaddrinfo(ai0); return pslist_reverse(sl_addr); }
/** * Handle reception of a /PI */ static void g2_node_handle_ping(gnutella_node_t *n, const g2_tree_t *t) { g2_tree_t *c; /* * Throttle pings received from UDP. */ if (NODE_IS_UDP(n)) { if (aging_lookup(g2_udp_pings, &n->addr)) { gnet_stats_count_dropped(n, MSG_DROP_THROTTLE); return; } aging_record(g2_udp_pings, WCOPY(&n->addr)); /* FALL THROUGH */ } c = g2_tree_first_child(t); /* * If there is no payload, it's a keep-alive ping, send back a pong. */ if (NULL == c) { g2_node_send_pong(n); return; } /* * There are children. * * If there is a /PI/UDP present, drop the message: we're not a hub, * we don't have to relay this message to its UDP target (we're only * connected to hubs, and the hub which got it should only forward that * message it its neighbouring hubs, not to leaves). * * If there is a /PI/RELAY, the ping was relayed by a hub, but it made * a mistake because we are a leaf node. */ g2_node_drop(G_STRFUNC, n, t, "has children and we are a leaf"); }
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ int RosenbrockIntegrator( /*~~~> Input: the initial condition at Tstart; Output: the solution at T */ KPP_REAL Y[], /*~~~> Input: integration interval */ KPP_REAL Tstart, KPP_REAL Tend , /*~~~> Input: tolerances */ KPP_REAL AbsTol[], KPP_REAL RelTol[], /*~~~> Input: ode function and its Jacobian */ void (*ode_Fun)(KPP_REAL, KPP_REAL [], KPP_REAL []), void (*ode_Jac)(KPP_REAL, KPP_REAL [], KPP_REAL []) , /*~~~> Input: The Rosenbrock method parameters */ int ros_S, KPP_REAL ros_M[], KPP_REAL ros_E[], KPP_REAL ros_A[], KPP_REAL ros_C[], KPP_REAL ros_Alpha[],KPP_REAL ros_Gamma[], KPP_REAL ros_ELO, char ros_NewF[], /*~~~> Input: integration parameters */ char Autonomous, char VectorTol, int Max_no_steps, KPP_REAL Roundoff, KPP_REAL Hmin, KPP_REAL Hmax, KPP_REAL Hstart, KPP_REAL FacMin, KPP_REAL FacMax, KPP_REAL FacRej, KPP_REAL FacSafe, /*~~~> Output: time at which the solution is returned (T=Tend if success) and last accepted step */ KPP_REAL *Texit, KPP_REAL *Hexit ) /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Template for the implementation of a generic Rosenbrock method defined by ros_S (no of stages) and coefficients ros_{A,C,M,E,Alpha,Gamma} returned value: IERR, indicator of success (if positive) or failure (if negative) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ { KPP_REAL Ynew[KPP_NVAR], Fcn0[KPP_NVAR], Fcn[KPP_NVAR], dFdT[KPP_NVAR], Jac0[KPP_LU_NONZERO], Ghimj[KPP_LU_NONZERO]; KPP_REAL K[KPP_NVAR*ros_S]; KPP_REAL H, T, Hnew, HC, HG, Fac, Tau; KPP_REAL Err, Yerr[KPP_NVAR]; int Pivot[KPP_NVAR], Direction, ioffset, j, istage; char RejectLastH, RejectMoreH; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /*~~~> INITIAL PREPARATIONS */ T = Tstart; *Hexit = 0.0; H = MIN(Hstart,Hmax); if (ABS(H) <= 10.0*Roundoff) H = DeltaMin; if (Tend >= Tstart) { Direction = +1; } else { Direction = -1; } /* end if */ RejectLastH=0; RejectMoreH=0; /*~~~> Time loop begins below */ while ( ( (Direction > 0) && ((T-Tend)+Roundoff <= ZERO) ) || ( (Direction < 0) && ((Tend-T)+Roundoff <= ZERO) ) ) { if ( Nstp > Max_no_steps ) { /* Too many steps */ *Texit = T; return ros_ErrorMsg(-6,T,H); } if ( ((T+0.1*H) == T) || (H <= Roundoff) ) { /* Step size too small */ *Texit = T; return ros_ErrorMsg(-7,T,H); } /*~~~> Limit H if necessary to avoid going beyond Tend */ *Hexit = H; H = MIN(H,ABS(Tend-T)); /*~~~> Compute the function at current time */ (*ode_Fun)(T,Y,Fcn0); /*~~~> Compute the function derivative with respect to T */ if (!Autonomous) ros_FunTimeDerivative ( T, Roundoff, Y, Fcn0, ode_Fun, dFdT ); /*~~~> Compute the Jacobian at current time */ (*ode_Jac)(T,Y,Jac0); /*~~~> Repeat step calculation until current step accepted */ while (1) { /* WHILE STEP NOT ACCEPTED */ if( ros_PrepareMatrix( &H, Direction, ros_Gamma[0], Jac0, Ghimj, Pivot) ) { /* More than 5 consecutive failed decompositions */ *Texit = T; return ros_ErrorMsg(-8,T,H); } /*~~~> Compute the stages */ for (istage = 1; istage <= ros_S; istage++) { /* Current istage offset. Current istage vector is K[ioffset:ioffset+KPP_NVAR-1] */ ioffset = KPP_NVAR*(istage-1); /* For the 1st istage the function has been computed previously */ if ( istage == 1 ) WCOPY(KPP_NVAR,Fcn0,1,Fcn,1); else { /* istage>1 and a new function evaluation is needed at current istage */ if ( ros_NewF[istage-1] ) { WCOPY(KPP_NVAR,Y,1,Ynew,1); for (j = 1; j <= istage-1; j++) WAXPY(KPP_NVAR,ros_A[(istage-1)*(istage-2)/2+j-1], &K[KPP_NVAR*(j-1)],1,Ynew,1); Tau = T + ros_Alpha[istage-1]*Direction*H; (*ode_Fun)(Tau,Ynew,Fcn); } /*end if ros_NewF(istage)*/ } /* end if istage */ WCOPY(KPP_NVAR,Fcn,1,&K[ioffset],1); for (j = 1; j <= istage-1; j++) { HC = ros_C[(istage-1)*(istage-2)/2+j-1]/(Direction*H); WAXPY(KPP_NVAR,HC,&K[KPP_NVAR*(j-1)],1,&K[ioffset],1); } /* for j */ if ((!Autonomous) && (ros_Gamma[istage-1])) { HG = Direction*H*ros_Gamma[istage-1]; WAXPY(KPP_NVAR,HG,dFdT,1,&K[ioffset],1); } /* end if !Autonomous */ SolveTemplate(Ghimj, Pivot, &K[ioffset]); } /* for istage */ /*~~~> Compute the new solution */ WCOPY(KPP_NVAR,Y,1,Ynew,1); for (j=1; j<=ros_S; j++) WAXPY(KPP_NVAR,ros_M[j-1],&K[KPP_NVAR*(j-1)],1,Ynew,1); /*~~~> Compute the error estimation */ WSCAL(KPP_NVAR,ZERO,Yerr,1); for (j=1; j<=ros_S; j++) WAXPY(KPP_NVAR,ros_E[j-1],&K[KPP_NVAR*(j-1)],1,Yerr,1); Err = ros_ErrorNorm ( Y, Ynew, Yerr, AbsTol, RelTol, VectorTol ); /*~~~> New step size is bounded by FacMin <= Hnew/H <= FacMax */ Fac = MIN(FacMax,MAX(FacMin,FacSafe/pow(Err,ONE/ros_ELO))); Hnew = H*Fac; /*~~~> Check the error magnitude and adjust step size */ Nstp++; if ( (Err <= ONE) || (H <= Hmin) ) { /*~~~> Accept step */ Nacc++; WCOPY(KPP_NVAR,Ynew,1,Y,1); T += Direction*H; Hnew = MAX(Hmin,MIN(Hnew,Hmax)); /* No step size increase after a rejected step */ if (RejectLastH) Hnew = MIN(Hnew,H); RejectLastH = 0; RejectMoreH = 0; H = Hnew; break; /* EXIT THE LOOP: WHILE STEP NOT ACCEPTED */ } else { /*~~~> Reject step */ if (Nacc >= 1) Nrej++; if (RejectMoreH) Hnew=H*FacRej; RejectMoreH = RejectLastH; RejectLastH = 1; H = Hnew; } /* end if Err <= 1 */ } /* while LOOP: WHILE STEP NOT ACCEPTED */ } /* while: time loop */ /*~~~> The integration was successful */ *Texit = T; return 1; } /* RosenbrockIntegrator */