bool PDSearchDirCalculator::ComputeSearchDirection() { DBG_START_METH("PDSearchDirCalculator::ComputeSearchDirection", dbg_verbosity); bool improve_solution = false; if (IpData().HaveDeltas()) { improve_solution = true; } bool retval; if (improve_solution && fast_step_computation_) { retval = true; } else { SmartPtr<IteratesVector> rhs = IpData().curr()->MakeNewContainer(); rhs->Set_x(*IpCq().curr_grad_lag_with_damping_x()); rhs->Set_s(*IpCq().curr_grad_lag_with_damping_s()); rhs->Set_y_c(*IpCq().curr_c()); rhs->Set_y_d(*IpCq().curr_d_minus_s()); Index nbounds = IpNLP().x_L()->Dim()+ IpNLP().x_U()->Dim() + IpNLP().d_L()->Dim()+ IpNLP().d_U()->Dim(); if (nbounds>0 && mehrotra_algorithm_) { // set up the right hand side a la Mehrotra DBG_ASSERT(IpData().HaveAffineDeltas()); DBG_ASSERT(!IpData().HaveDeltas()); const SmartPtr<const IteratesVector> delta_aff = IpData().delta_aff(); SmartPtr<Vector> tmpvec = delta_aff->z_L()->MakeNew(); IpNLP().Px_L()->TransMultVector(1., *delta_aff->x(), 0., *tmpvec); tmpvec->ElementWiseMultiply(*delta_aff->z_L()); tmpvec->Axpy(1., *IpCq().curr_relaxed_compl_x_L()); rhs->Set_z_L(*tmpvec); tmpvec = delta_aff->z_U()->MakeNew(); IpNLP().Px_U()->TransMultVector(-1., *delta_aff->x(), 0., *tmpvec); tmpvec->ElementWiseMultiply(*delta_aff->z_U()); tmpvec->Axpy(1., *IpCq().curr_relaxed_compl_x_U()); rhs->Set_z_U(*tmpvec); tmpvec = delta_aff->v_L()->MakeNew(); IpNLP().Pd_L()->TransMultVector(1., *delta_aff->s(), 0., *tmpvec); tmpvec->ElementWiseMultiply(*delta_aff->v_L()); tmpvec->Axpy(1., *IpCq().curr_relaxed_compl_s_L()); rhs->Set_v_L(*tmpvec); tmpvec = delta_aff->v_U()->MakeNew(); IpNLP().Pd_U()->TransMultVector(-1., *delta_aff->s(), 0., *tmpvec); tmpvec->ElementWiseMultiply(*delta_aff->v_U()); tmpvec->Axpy(1., *IpCq().curr_relaxed_compl_s_U()); rhs->Set_v_U(*tmpvec); } else { rhs->Set_z_L(*IpCq().curr_relaxed_compl_x_L()); rhs->Set_z_U(*IpCq().curr_relaxed_compl_x_U()); rhs->Set_v_L(*IpCq().curr_relaxed_compl_s_L()); rhs->Set_v_U(*IpCq().curr_relaxed_compl_s_U()); } DBG_PRINT_VECTOR(2, "rhs", *rhs); // Get space for the search direction SmartPtr<IteratesVector> delta = IpData().curr()->MakeNewIteratesVector(true); if (improve_solution) { // We can probably avoid copying and scaling... delta->AddOneVector(-1., *IpData().delta(), 0.); } bool& allow_inexact = fast_step_computation_; retval = pd_solver_->Solve(-1.0, 0.0, *rhs, *delta, allow_inexact, improve_solution); if (retval) { // Store the search directions in the IpData object IpData().set_delta(delta); } } return retval; }
bool IpoptData::InitializeDataStructures(IpoptNLP& ip_nlp, bool want_x, bool want_y_c, bool want_y_d, bool want_z_L, bool want_z_U) { DBG_ASSERT(initialize_called_); /* * Allocate space for all the required linear algebra * structures */ SmartPtr<Vector> new_x; SmartPtr<Vector> new_s; SmartPtr<Vector> new_y_c; SmartPtr<Vector> new_y_d; SmartPtr<Vector> new_z_L; SmartPtr<Vector> new_z_U; SmartPtr<Vector> new_v_L; SmartPtr<Vector> new_v_U; // Get the required linear algebra structures from the model bool retValue = ip_nlp.InitializeStructures(new_x, want_x, new_y_c, want_y_c, new_y_d, want_y_d, new_z_L, want_z_L, new_z_U, want_z_U, new_v_L, new_v_U); if (!retValue) { return false; } new_s = new_y_d->MakeNew(); // same dimension as d iterates_space_ = new IteratesVectorSpace(*(new_x->OwnerSpace()), *(new_s->OwnerSpace()), *(new_y_c->OwnerSpace()), *(new_y_d->OwnerSpace()), *(new_z_L->OwnerSpace()), *(new_z_U->OwnerSpace()), *(new_v_L->OwnerSpace()), *(new_v_U->OwnerSpace()) ); curr_ = iterates_space_->MakeNewIteratesVector(*new_x, *new_s, *new_y_c, *new_y_d, *new_z_L, *new_z_U, *new_v_L, *new_v_U); #if COIN_IPOPT_CHECKLEVEL > 0 debug_curr_tag_ = curr_->GetTag(); debug_curr_tag_sum_ = curr_->GetTagSum(); debug_trial_tag_ = 0; debug_trial_tag_sum_ = 0; debug_delta_tag_ = 0; debug_delta_tag_sum_ = 0; debug_delta_aff_tag_ = 0; debug_delta_aff_tag_sum_ = 0; #endif trial_ = NULL; // Set the pointers for storing steps to NULL delta_ = NULL; delta_aff_ = NULL; have_prototypes_ = true; have_deltas_ = false; have_affine_deltas_ = false; return cgpen_data_->InitializeDataStructures(); }
/*************** send function - tcp_full only ***********************/ size_t send(const void *data_ptr, size_t data_len) throw() { DBG_ASSERT(tcp_full); return tcp_full->send(data_ptr, data_len); }
/*! \brief Log an error entry in the system log Log an error entry in the system log. \param Fdo Pointer to a DEVICE_OBJECT structure. This is the device object for the target device, previously created by the driver's AddDevice routine. \param ErrorCode The NTSTATUS code which should be reported on behalf of this error log entry \param String1 Pointer to the 1st (WCHAR) string which has to be included into the error log entry. This can be NULL if no string is to be inserted. \param String2 Pointer to the 2nd (WCHAR) string which has to be included into the error log entry. This can be NULL if no string is to be inserted. */ VOID LogError(IN PDEVICE_OBJECT Fdo, IN NTSTATUS ErrorCode, const WCHAR *String1, const WCHAR *String2) { USHORT stringSize; USHORT stringOffset; USHORT stringSize1; USHORT stringSize2; USHORT size; USHORT numberOfStrings; FUNC_ENTER(); // IoAllocateErrorLogEntry() and IoWriteErrorLogEntry() require this DBG_IRQL( <= DISPATCH_LEVEL); // calculate the size of the strings numberOfStrings = 0; // Check if there is a string 1, and calculate its size // (including the trailing zero) stringSize1 = String1 ? (++numberOfStrings, sizeof(WCHAR) * (wcslen(String1) + 1)) : 0; // Check if there is a string 2, and calculate its size // (including the trailing zero) stringSize2 = String2 ? (++numberOfStrings, sizeof(WCHAR) * (wcslen(String2) + 1)) : 0; // Add the sizes of both strings // This is the size of what has to be added to the error log entry stringSize = stringSize1 + stringSize2; // Offset where the string(s) will be written into the error log entry stringOffset = sizeof(IO_ERROR_LOG_PACKET); // The complete size of the event log entry size = stringOffset + stringSize; // Make sure we don't need more space than needed. // For debugging purposes, have an DBG_ASSERT(). Anyway, // in the wild, don't do anything if the size is too big. // Remember: Not being able to write a log is not an error! /*! \todo Would it make sense to short the strings if the * error log entry would be too big? */ DBG_ASSERT(size <= ERROR_LOG_MAXIMUM_SIZE); if (size <= ERROR_LOG_MAXIMUM_SIZE) { PIO_ERROR_LOG_PACKET pentry; // allocate the entry for the error log DBG_IRQL( <= DISPATCH_LEVEL); pentry = IoAllocateErrorLogEntry(Fdo, (UCHAR) size); DBG_ASSERT(pentry); if (pentry) { // clear the complete entry (to be sure) RtlZeroMemory(pentry, sizeof(*pentry)); // Write the relevant entries pentry->NumberOfStrings = numberOfStrings; pentry->StringOffset = stringOffset; pentry->ErrorCode = ErrorCode; // If there was a string1, write that into the entry if (String1) { wcscpy((wchar_t*)&((UCHAR*)pentry)[stringOffset], String1); } // If there was a string2, write that into the entry if (String2) { wcscpy((wchar_t*)&((UCHAR*)pentry)[stringOffset + stringSize1], String2); } // Now, give that entry to the system DBG_IRQL( <= DISPATCH_LEVEL); IoWriteErrorLogEntry(pentry); } }
/*:::::*/ FBCALL int fb_ExecEx ( FBSTRING *program, FBSTRING *args, int do_fork ) { char buffer[MAX_PATH+1], *application, *arguments, **argv, *p; int i, argc = 0, res = -1, status, len_program, len_arguments; pid_t pid; if( (program == NULL) || (program->data == NULL) ) { fb_hStrDelTemp( args ); fb_hStrDelTemp( program ); return -1; } application = fb_hGetShortPath( program->data, buffer, MAX_PATH ); DBG_ASSERT( application!=NULL ); if( application==program->data ) { len_program = FB_STRSIZE( program ); application = buffer; FB_MEMCPY(application, program->data, len_program ); application[len_program] = 0; } fb_hConvertPath( application ); if( args==NULL ) { arguments = ""; } else { len_arguments = FB_STRSIZE( args ); arguments = alloca( len_arguments + 1 ); DBG_ASSERT( arguments!=NULL ); arguments[len_arguments] = 0; if( len_arguments ) argc = fb_hParseArgs( arguments, args->data, len_arguments ); } FB_STRLOCK(); fb_hStrDelTemp_NoLock( args ); fb_hStrDelTemp_NoLock( program ); FB_STRUNLOCK(); if( argc == -1 ) return -1; argc++; /* add 1 for program name */ argv = alloca( sizeof(char*) * (argc + 1 )); DBG_ASSERT( argv!=NULL ); argv[0] = application; /* scan the processed args and set pointers */ p = arguments; for( i=1 ; i<argc; i++) { argv[i] = p; /* set pointer to current argument */ while( *p++ ); /* skip to 1 char past next null char */ } argv[argc] = NULL; /* Launch */ fb_hExitConsole(); if( do_fork ) { pid = fork(); if( pid != -1 ) { if (pid == 0) { /* execvp() only returns if it failed */ execvp( application, argv ); /* HACK: execvp() failed, this must be communiated to the parent process *somehow*, so fb_ExecEx() can return -1 there */ exit( 255 ); /* FIXME: won't be able to tell the difference if the exec'ed program returned 255. Maybe a pipe could be used instead of the 255 exit code? Unless that's too slow/has side-effects */ } else if( (waitpid(pid, &status, 0) > 0) && WIFEXITED(status) ) { res = WEXITSTATUS(status); if( res == 255 ) { /* See the HACK above */ res = -1; } } } } else { res = execvp( application, argv ); } fb_hInitConsole(); return res; }
/** Method for retrieving the value of an option. Calling this * method will increase the counter by one. */ std::string GetValue() const { DBG_ASSERT(initialized_); counter_++; return value_; }
/** Method for accessing current value of the request counter */ Index Counter() const { DBG_ASSERT(initialized_); return counter_; }
Index CompoundSymMatrixSpace::GetBlockDim(Index irow_jcol) const { DBG_ASSERT(dimensions_set_ && "Cannot get block dimensions before all dimensions are set."); DBG_ASSERT(irow_jcol < ncomp_spaces_); return block_dim_[irow_jcol]; }
void CompoundSymMatrix::MultVectorImpl(Number alpha, const Vector &x, Number beta, Vector &y) const { if (!matrices_valid_) { matrices_valid_ = MatricesValid(); } DBG_ASSERT(matrices_valid_); // The vectors are assumed to be compound Vectors as well const CompoundVector* comp_x = static_cast<const CompoundVector*>(&x); DBG_ASSERT(dynamic_cast<const CompoundVector*>(&x)); CompoundVector* comp_y = static_cast<CompoundVector*>(&y); DBG_ASSERT(dynamic_cast<CompoundVector*>(&y)); // A few sanity checks if (comp_x) { DBG_ASSERT(NComps_Dim()==comp_x->NComps()); } else { DBG_ASSERT(NComps_Dim() == 1); } if (comp_y) { DBG_ASSERT(NComps_Dim()==comp_y->NComps()); } else { DBG_ASSERT(NComps_Dim() == 1); } // Take care of the y part of the addition if ( beta!=0.0 ) { y.Scal(beta); } else { y.Set(0.0); // In case y hasn't been initialized yet } for (Index irow=0; irow<NComps_Dim(); irow++) { SmartPtr<Vector> y_i; if (comp_y) { y_i = comp_y->GetCompNonConst(irow); } else { y_i = &y; } DBG_ASSERT(IsValid(y_i)); for (Index jcol=0; jcol<=irow; jcol++) { SmartPtr<const Vector> x_j; if (comp_x) { x_j = comp_x->GetComp(irow); } else { x_j = &x; } DBG_ASSERT(IsValid(x_j)); if (ConstComp(irow,jcol)) { ConstComp(irow,jcol)->MultVector(alpha, *comp_x->GetComp(jcol), 1., *comp_y->GetCompNonConst(irow)); } } for (Index jcol = irow+1; jcol < NComps_Dim(); jcol++) { if (ConstComp(jcol,irow)) { ConstComp(jcol,irow)->TransMultVector(alpha, *comp_x->GetComp(jcol), 1., *comp_y->GetCompNonConst(irow)); } } } }
// Reference this object by increasing the reference count void GTObject::AddReference(void) { DBG_ASSERT(m_nReferenceCount > 0); m_nReferenceCount++; }
explicit _TreeImpMetadataBase(PyObject * seq, PyObject * metadata, const LT & lt) : BaseT(seq, MetadataT(metadata), lt) { DBG_ASSERT(seq != NULL); }
bool OptionsList::ReadFromStream(const Journalist& jnlst, std::istream& is) { jnlst.Printf(J_DETAILED, J_MAIN, "Start reading options from stream.\n"); while (true) { std::string tag; std::string value; if (!readnexttoken(is, tag)) { // That's it - end of file reached. jnlst.Printf(J_DETAILED, J_MAIN, "Finished reading options from file.\n"); return true; } if (!readnexttoken(is, value)) { // Can't read value for a given tag jnlst.Printf(J_ERROR, J_MAIN, "Error reading value for tag %s from file.\n", tag.c_str()); return false; } // Now add the value for the options list jnlst.Printf(J_DETAILED, J_MAIN, "Adding option \"%s\" with value \"%s\" to OptionsList.\n", tag.c_str(), value.c_str()); if (IsValid(reg_options_)) { SmartPtr<const RegisteredOption> option = reg_options_->GetOption(tag); if (IsNull(option)) { std::string msg = "Read Option: "; msg += tag; msg += ". It is not a valid option. Check the list of available options."; THROW_EXCEPTION(OPTION_INVALID, msg); } if (option->Type() == OT_String) { bool result = SetStringValue(tag, value, false); ASSERT_EXCEPTION(result, OPTION_INVALID, "Error setting string value read from option file."); } else if (option->Type() == OT_Number) { char* p_end; Number retval = strtod(value.c_str(), &p_end); if (*p_end!='\0' && !isspace(*p_end)) { std::string msg = "Option \"" + tag + "\": Double value expected, but non-numeric option value \"" + value + "\" found.\n"; THROW_EXCEPTION(OPTION_INVALID, msg); } bool result = SetNumericValue(tag, retval, false); ASSERT_EXCEPTION(result, OPTION_INVALID, "Error setting numeric value read from file."); } else if (option->Type() == OT_Integer) { char* p_end; Index retval = strtol(value.c_str(), &p_end, 10); if (*p_end!='\0' && !isspace(*p_end)) { std::string msg = "Option \"" + tag + "\": Integer value expected, but non-integer option value \"" + value + "\" found.\n"; if (IsValid(jnlst_)) { option->OutputDescription(*jnlst_); } THROW_EXCEPTION(OPTION_INVALID, msg); } bool result = SetIntegerValue(tag, retval, false); ASSERT_EXCEPTION(result, OPTION_INVALID, "Error setting integer value read from option file."); } else { DBG_ASSERT(false && "Option Type: Unknown"); } } else { bool result = SetStringValue(tag, value, false); ASSERT_EXCEPTION(result, OPTION_INVALID, "Error setting value read from option file."); } } }
/** Returns the scaling strategy object */ SmartPtr<NLPScalingObject> NLP_scaling() const { DBG_ASSERT(IsValid(nlp_scaling_)); return nlp_scaling_; }
/** * callback to received data from the vdev * - if a established tunnel exist, send the packet to it * - if a tunnel is currently in establishment, set the triggering packet * - if no tunnel exist, start the establishement on one */ static void onet_vdev_in( void *userptr, int ethertype, char *pkt, int pkt_len ) { struct iphdr *iph = (struct iphdr *)pkt; onet_t *onet = onet_main; onet_tunnel_t *tunnel; ip_addr_t dst_iaddr; DBG("enter ethertype=0x%x\n", ethertype ); // handle only ipv4 for now EXP_ASSERT( ethertype == ETHERTYPE_IP ); // sanity check // TODO put the basic check of the ipv4 packet in a function if( pkt_len < sizeof(*iph) ){ LOG(0,"received bogus packet of %d-byte. not even big enought for an ipv4 header\n", pkt_len ); return; } if( pkt_len < iph->ihl*4 ){ LOG(0,"received bogus packet of %d-byte with ipv4_hd->ihl=%d\n", pkt_len, iph->ihl*4 ); return; } // get the destination ip address from the packet ip_addr_v4_set( &dst_iaddr, ntohl(iph->daddr) ); // find a existing tunnel if there is any tunnel = onet_tunnel_from_remote_iaddr( &dst_iaddr ); // if there is a tunnel and the connection is already established, send it thru it if( tunnel && tunnel->stun ){ DBG("there is already a establish link for this packet \n"); // TMP: just to test the limitor if( rate_limit_exceeded( tunnel->thput_limit) ){ // LOGM_ERR("packet discarded due to rate limiter\n"); return; } // update the pkt_rate and throughput rate_estim_add( tunnel->pkt_rate, 1 ); rate_estim_add( tunnel->throughput, pkt_len ); // send the packet stun_out_data( tunnel->stun, ethertype, pkt, pkt_len ); return; } // if the ipaddr is in the dst_iaddr_negcache, return if( dst_iaddr_negcache_is_present( onet->dst_iaddr_negcache, &dst_iaddr) ){ // return an ICMP if the ip record is in the dst_iaddr_negcache // - apply the concept of not replying a icmp immediatly to let // the time to resolve the address // - similar to the time to solve the hw address with ARP // - as in rfc2461.7.2.2, ICMP must be replied after 3sec // - it is ONET_DELAY_B4_ICMP // TODO the timer aspect isnt well respected now // - itor has its own timer see bug 359 // - onet_ns_req_dst_iaddr_* honor it tho raw_icmp_reply_send( ICMP_DEST_UNREACH, ICMP_HOST_UNREACH, 0, pkt, pkt_len ); return; } // if there no record for this dst_iaddr in the local database, discard the packet if( onet_ns_req_dst_iaddr_test( &dst_iaddr ) ){ DBG("received packet for which im unable to find a rdvpoint\n" ); return; } // if a establishing tunnel exists, update the trigerring packet if( tunnel ){ DBG_ASSERT( tunnel->itor ); // update the trigger packet onet_tunnel_itor_trigger_pkt_set( tunnel, ethertype, pkt, pkt_len ); DBG("tunnel is currently in establishement for this packet\n"); return; } DBG_ASSERT( !tunnel ); // create a tunnel as itor tunnel = onet_tunnel_open_itor( &dst_iaddr ); if( !tunnel ){ LOGM_ERR("can't initiate a tunnel toward the iaddr %s\n", ip_addr_str( &dst_iaddr ) ); return; } // set the trigger packet onet_tunnel_itor_trigger_pkt_set( tunnel, ethertype, pkt, pkt_len ); }
/** True if the option can be overwritten */ bool AllowClobber() const { DBG_ASSERT(initialized_); return allow_clobber_; }
virtual ~ReferencedObject() { DBG_ASSERT(reference_count_ == 0); }
/** True if this option is not to show up in the * print_user_options output */ bool DontPrint() const { DBG_ASSERT(initialized_); return dont_print_; }
double* WsmpSolverInterface::GetValuesArrayPtr() { DBG_ASSERT(initialized_); DBG_ASSERT(a_); return a_; }
/** Method for retrieving the value without increasing the * counter */ std::string Value() const { DBG_ASSERT(initialized_); return value_; }
Index WsmpSolverInterface::NumberOfNegEVals() const { DBG_START_METH("WsmpSolverInterface::NumberOfNegEVals",dbg_verbosity); DBG_ASSERT(negevals_>=0); return negevals_; }
/*! \brief Executes IOCTLs Executes IRPs containing the IRP_MJ_DEVICE_CONTROL I/O function code. \param Pdx Pointer to the DEVICE_EXTENSION structure. \param Irp Pointer to an IRP structure that describes the requested I/O operation. \return If the routine succeeds, it returns STATUS_SUCCESS. Otherwise, it return one of the error status values: \n STATUS_SUCCESS - Success. \n STATUS_BUFFER_TOO_SMALL - Buffer too small. This function does not perform any validity checks on the input and output buffer! This should already been done in cbm_devicecontrol. */ NTSTATUS cbm_execute_devicecontrol(IN PDEVICE_EXTENSION Pdx, IN PIRP Irp) { PPAR_SET_INFORMATION setInfo; PIO_STACK_LOCATION irpSp; ULONG_PTR returnLength; NTSTATUS ntStatus; FUNC_ENTER(); // As not every IOCTL needs to return a value, we initialize // the return length here. This way, it needs only be altered // if the IOCTL returns some value. returnLength = 0; // get the current IRP stack location irpSp = IoGetCurrentIrpStackLocation(Irp); PERF_EVENT_IOCTL_EXECUTE(irpSp->Parameters.DeviceIoControl.IoControlCode); DBG_IRPPATH_EXECUTE("Execute Ioctl"); // Call the appropriate function for processing the IOCTL // PrimaryAddresses are ANDed with 0x1F, as these are the only legitimate // primary addresses allowed for a IEC serial bus. switch (irpSp->Parameters.DeviceIoControl.IoControlCode) { case CBMCTRL_TALK: DBG_IRP(CBMCTRL_TALK); ntStatus = cbmiec_talk(Pdx, INPUTVALUE(CBMT_TALK_IN)->PrimaryAddress & 0x1F, INPUTVALUE(CBMT_TALK_IN)->SecondaryAddress); break; case CBMCTRL_LISTEN: DBG_IRP(CBMCTRL_LISTEN); ntStatus = cbmiec_listen(Pdx, INPUTVALUE(CBMT_LISTEN_IN)->PrimaryAddress & 0x1F, INPUTVALUE(CBMT_LISTEN_IN)->SecondaryAddress); break; case CBMCTRL_UNTALK: DBG_IRP(CBMCTRL_UNTALK); ntStatus = cbmiec_untalk(Pdx); break; case CBMCTRL_UNLISTEN: DBG_IRP(CBMCTRL_UNLISTEN); ntStatus = cbmiec_unlisten(Pdx); break; case CBMCTRL_OPEN: DBG_IRP(CBMCTRL_OPEN); ntStatus = cbmiec_open(Pdx, INPUTVALUE(CBMT_OPEN_IN)->PrimaryAddress & 0x1F, INPUTVALUE(CBMT_OPEN_IN)->SecondaryAddress); break; case CBMCTRL_CLOSE: DBG_IRP(CBMCTRL_CLOSE); ntStatus = cbmiec_close(Pdx,INPUTVALUE(CBMT_CLOSE_IN)->PrimaryAddress & 0x1F, INPUTVALUE(CBMT_CLOSE_IN)->SecondaryAddress); break; case CBMCTRL_RESET: DBG_IRP(CBMCTRL_RESET); ntStatus = cbmiec_reset(Pdx); break; case CBMCTRL_GET_EOI: DBG_IRP(CBMCTRL_GET_EOI); returnLength = sizeof(CBMT_GET_EOI_OUT); ntStatus = cbmiec_get_eoi(Pdx, &(OUTPUTVALUE(CBMT_GET_EOI_OUT)->Decision)); break; case CBMCTRL_CLEAR_EOI: DBG_IRP(CBMCTRL_CLEAR_EOI); ntStatus = cbmiec_clear_eoi(Pdx); break; case CBMCTRL_PP_READ: DBG_IRP(CBMCTRL_PP_READ); ntStatus = cbm_checkoutputbuffer(irpSp, sizeof(CBMT_PP_READ_OUT), STATUS_SUCCESS); returnLength = sizeof(CBMT_PP_READ_OUT); ntStatus = cbmiec_pp_read(Pdx, &(OUTPUTVALUE(CBMT_PP_READ_OUT)->Byte)); break; case CBMCTRL_PP_WRITE: DBG_IRP(CBMCTRL_PP_WRITE); ntStatus = cbmiec_pp_write(Pdx, INPUTVALUE(CBMT_PP_WRITE_IN)->Byte); break; case CBMCTRL_IEC_POLL: DBG_IRP(CBMCTRL_IEC_POLL); returnLength = sizeof(CBMT_IEC_POLL_OUT); ntStatus = cbmiec_iec_poll(Pdx, &(OUTPUTVALUE(CBMT_IEC_POLL_OUT)->Line)); break; case CBMCTRL_IEC_SET: DBG_IRP(CBMCTRL_IEC_SET); ntStatus = cbmiec_iec_set(Pdx, INPUTVALUE(CBMT_IEC_SET_IN)->Line); break; case CBMCTRL_IEC_RELEASE: DBG_IRP(CBMCTRL_IEC_RELEASE); ntStatus = cbmiec_iec_release(Pdx, INPUTVALUE(CBMT_IEC_RELEASE_IN)->Line); break; case CBMCTRL_IEC_SETRELEASE: DBG_IRP(CBMCTRL_IEC_SETRELEASE); ntStatus = cbmiec_iec_setrelease(Pdx, INPUTVALUE(CBMT_IEC_SETRELEASE_IN)->State, INPUTVALUE(CBMT_IEC_SETRELEASE_IN)->Line); break; case CBMCTRL_IEC_WAIT: DBG_IRP(CBMCTRL_IEC_WAIT); returnLength = sizeof(CBMT_IEC_WAIT_OUT); ntStatus = cbmiec_iec_wait(Pdx, INPUTVALUE(CBMT_IEC_WAIT_IN)->Line, INPUTVALUE(CBMT_IEC_WAIT_IN)->State, &(OUTPUTVALUE(CBMT_IEC_WAIT_OUT)->Line)); break; case CBMCTRL_PARBURST_READ: DBG_IRP(CBMCTRL_PARBURST_READ); returnLength = irpSp->Parameters.DeviceIoControl.OutputBufferLength; ntStatus = cbmiec_parallel_burst_read(Pdx, &(OUTPUTVALUE(CBMT_PARBURST_PREAD_OUT)->Byte)); break; case CBMCTRL_PARBURST_WRITE: DBG_IRP(CBMCTRL_PARBURST_READ); returnLength = irpSp->Parameters.DeviceIoControl.OutputBufferLength; ntStatus = cbmiec_parallel_burst_write(Pdx, INPUTVALUE(CBMT_PARBURST_PWRITE_IN)->Byte); break; case CBMCTRL_PARBURST_READ_TRACK: DBG_IRP(CBMCTRL_PARBURST_READ_TRACK); returnLength = irpSp->Parameters.DeviceIoControl.OutputBufferLength; ntStatus = cbmiec_parallel_burst_read_track(Pdx, Irp->AssociatedIrp.SystemBuffer, (ULONG) returnLength); break; case CBMCTRL_PARBURST_WRITE_TRACK: DBG_IRP(CBMCTRL_PARBURST_WRITE_TRACK); returnLength = irpSp->Parameters.DeviceIoControl.InputBufferLength; ntStatus = cbmiec_parallel_burst_write_track(Pdx, Irp->AssociatedIrp.SystemBuffer, (ULONG) returnLength); break; case CBMCTRL_I_INSTALL: DBG_IRP(CBMCTRL_I_INSTALL); returnLength = irpSp->Parameters.DeviceIoControl.OutputBufferLength; ntStatus = cbm_install(Pdx, OUTPUTVALUE(CBMT_I_INSTALL_OUT), (PULONG) &returnLength); break; case CBMCTRL_PARPORT_LOCK: DBG_IRP(CBMCTRL_PARPORT_LOCK); ntStatus = cbm_lock(Pdx); break; case CBMCTRL_PARPORT_UNLOCK: DBG_IRP(CBMCTRL_PARPORT_UNLOCK); ntStatus = cbm_unlock(Pdx); break; case CBMCTRL_UPDATE: DBG_IRP(CBMCTRL_UPDATE); cbm_init_registry(NULL, Pdx); ntStatus = STATUS_SUCCESS; break; #if DBG case CBMCTRL_I_READDBG: DBG_IRP(CBMCTRL_I_READDBG); returnLength = irpSp->Parameters.DeviceIoControl.OutputBufferLength; ntStatus = cbm_dbg_readbuffer(Pdx, OUTPUTVALUE(CHAR), (PULONG) &returnLength); break; #endif // #if DBG default: // As cbm_devicecontrol() already checked the IRP, // this piece of code should never be entered. If it // is, this is a sign of a forgotten IOCTL, or a severe // programming error DBG_ERROR((DBG_PREFIX "unknown IRP_MJ_DEVICE_CONTROL")); DBG_ASSERT(("THIS SHOULD NOT HAPPEN!", 0)); ntStatus = STATUS_INVALID_PARAMETER; break; } // If an error occurred, make sure not to return anything. if (!NT_SUCCESS(ntStatus)) { returnLength = 0; } // Complete the request: DBG_IRPPATH_COMPLETE("Execute Ioctl"); QueueCompleteIrp(&Pdx->IrpQueue, Irp, ntStatus, returnLength); FUNC_LEAVE_NTSTATUS(ntStatus); }
ESymSolverStatus WsmpSolverInterface:: DetermineDependentRows(const Index* ia, const Index* ja, std::list<Index>& c_deps) { DBG_START_METH("WsmpSolverInterface::DetermineDependentRows", dbg_verbosity); c_deps.clear(); ASSERT_EXCEPTION(!wsmp_no_pivoting_, OPTION_INVALID, "WSMP dependency detection does not work without pivoting."); if (!have_symbolic_factorization_) { ESymSolverStatus retval = InternalSymFact(ia, ja, 0); if (retval != SYMSOLVER_SUCCESS) { return retval; } have_symbolic_factorization_ = true; } // Call WSSMP for numerical factorization to detect degenerate // rows/columns ipfint N = dim_; ipfint NAUX = 0; IPARM_[1] = 3; // numerical factorization IPARM_[2] = 3; // numerical factorization DPARM_[10] = wsmp_pivtol_; // set current pivot tolerance ipfint idmy; double ddmy; #ifdef PARDISO_MATCHING_PREPROCESS F77_FUNC(wssmp,WSSMP)(&N, ia2, ja2, a2_, &ddmy, PERM_, INVP_, &ddmy, &idmy, &idmy, &ddmy, &NAUX, MRP_, IPARM_, DPARM_); #else F77_FUNC(wssmp,WSSMP)(&N, ia, ja, a_, &ddmy, PERM_, INVP_, &ddmy, &idmy, &idmy, &ddmy, &NAUX, MRP_, IPARM_, DPARM_); #endif const Index ierror = IPARM_[63]; if (ierror == 0) { int ii = 0; for (int i=0; i<N; i++) { if (MRP_[i] == -1) { c_deps.push_back(i); ii++; } } DBG_ASSERT(ii == IPARM_[20]); } if (ierror > 0) { Jnlst().Printf(J_DETAILED, J_LINEAR_ALGEBRA, "WSMP detected that the matrix is singular and encountered %d zero pivots.\n", dim_+1-ierror); if (HaveIpData()) { IpData().TimingStats().LinearSystemFactorization().End(); } return SYMSOLVER_SINGULAR; } else if (ierror != 0) { if (ierror == -102) { Jnlst().Printf(J_ERROR, J_LINEAR_ALGEBRA, "Error: WSMP is not able to allocate sufficient amount of memory during factorization.\n"); } else { Jnlst().Printf(J_ERROR, J_LINEAR_ALGEBRA, "Error in WSMP during factorization phase.\n Error code is %d.\n", ierror); } if (HaveIpData()) { IpData().TimingStats().LinearSystemFactorization().End(); } return SYMSOLVER_FATAL_ERROR; } return SYMSOLVER_SUCCESS; }
/** \brief parse a bt_utmsgtype_t::HANDSHAKE * * @return a tokeep for the bt_swarm_full_t */ bool bt_swarm_full_utmsg_t::parse_handshake(pkt_t &pkt) throw() { bt_swarm_t * bt_swarm = swarm_full->get_swarm(); bt_swarm_utmsg_t * swarm_utmsg = bt_swarm->swarm_utmsg(); // log to debug KLOG_DBG("enter pkt=" << pkt); // convert the handshake message body to a dvar_t dvar_t handshake_dvar = bencode_t::to_dvar(pkt.to_datum(datum_t::NOCOPY)); // if the handshake_dvar failed to parse the bencoded data, return an error if( handshake_dvar.is_null() || handshake_dvar.type() != dvar_type_t::MAP ) return parsing_error("unable to find handshake_dvar as dvar_type_t::MAP"); // get the prog_version if available if( handshake_dvar.map().contain("v", dvar_type_t::STRING) ) remote_prog_version = handshake_dvar.map()["v"].str().get(); // get the tcp_listen_port if available if( handshake_dvar.map().contain("p", dvar_type_t::INTEGER) ){ uint16_t tcp_listen_port = handshake_dvar.map()["p"].integer().get(); // build the remote_tcp_listen_ipport from the connection remote_addr and listen port remote_tcp_listen_ipport = swarm_full->remote_addr().get_peerid_vapi()->to_string() + std::string(":") + OSTREAMSTR(tcp_listen_port); // if tcp_listen_port is 0, nullify remote_tcp_listen_ipport if( tcp_listen_port == 0 ) remote_tcp_listen_ipport = ipport_addr_t(); } // if the handshake_dvar doesnt contains the convtable map, return now if( !handshake_dvar.map().contain("m", dvar_type_t::MAP) ) return true; // create an alias on the convtable_dvar const dvar_map_t &convtable_dvar = handshake_dvar.map()["m"].map(); // parse the convtable for each registered bt_utmsg_vapi_t const bt_swarm_utmsg_t::utmsg_vapi_db_t &utmsg_vapi_db = swarm_utmsg->utmsg_vapi_db(); bt_swarm_utmsg_t::utmsg_vapi_db_t::const_iterator iter; for(iter = utmsg_vapi_db.begin(); iter != utmsg_vapi_db.end(); iter++){ bt_utmsg_vapi_t * utmsg_vapi = *iter; bt_utmsgtype_t bt_utmsgtype = utmsg_vapi->utmsgtype(); std::string utmsgstr = utmsg_vapi->utmsgstr(); // if this utmsg is not supported by remove peer, goto the next if( !convtable_dvar.contain(utmsgstr, dvar_type_t::INTEGER) ) continue; // get the opcode used by the remote peer uint8_t opcode = convtable_dvar[utmsgstr].integer().get(); // if the new opcode is 0, DO NOT add it and goes to the next // - if an opcode is 0, this mean disable the option if( opcode == 0 ){ // if bt_utmsgtype_t is not in convtable_db, goto the next // - this means a bug in the remote peer as it put a 0 opcode for // an extension which has not yet been initialized if( convtable_db.find(bt_utmsgtype) == convtable_db.end() ) continue; // sanity check - the cnx_vapi_db MUST contain the bt_utmsgtype_t too DBG_ASSERT( cnx_vapi_db.find(bt_utmsgtype) != cnx_vapi_db.end() ); // delete the cnx_vapi object bt_utmsg_cnx_vapi_t * cnx_vapi = cnx_vapi_db.find(bt_utmsgtype)->second; nipmem_delete cnx_vapi; // remote this bt_utmsgtype_t from both database cnx_vapi_db.erase(bt_utmsgtype); convtable_db.erase(bt_utmsgtype); continue; } // insert/update this bt_utmsgtype to the convtable_db convtable_db[bt_utmsgtype] = opcode; // create the bt_utmsg_cnx_vapi_t - if not yet initialized // - it links itself to the bt_swarm_full_utmsg_t if( cnx_vapi_db.find(bt_utmsgtype) == cnx_vapi_db.end() ){ bt_utmsg_cnx_vapi_t * cnx_vapi = utmsg_vapi->cnx_ctor(this); DBG_ASSERT( cnx_vapi ); } } // return no error return true; }
static void tran_send(pbuf_t *pbuf) { DBG_ASSERT(pbuf != NULL __DBG_LINE); #if M_SLOT_EN > 0 uint32_t send_need_time = LEN_TO_US(pbuf->data_len); uint32_t slot_remain_time = TICK_TO_US(m_slot_get_remain_time()); #else uint32_t send_need_time = 0; uint32_t slot_remain_time = 0xFFFFFFFF; #endif if ((pbuf != NULL) && (slot_remain_time > send_need_time)) { uint8_t stamp_size = 0; #if M_SYNC_EN > 0 stamp_size = m_sync_txfilter(pbuf); #endif if (!phy_write_buf(pbuf, stamp_size)) { #if M_TRAN_DGB_EN > 0 static uint32_t tx_write_fifo_fail_cnt = 0; tx_write_fifo_fail_cnt++; #endif tran_send_failed(); return; } tran_state.tx_und_happend = FALSE; if (!phy_send_data()) { tran_send_failed(); return; } #if M_TRAN_DGB_EN > 0 m_tran_tracker.data_send_real++; #endif #if TXOK_INT_SIMU_EN > 0 HAL_TIMER_SET_REL(US_TO_TICK(LEN_TO_US(pbuf->data_len) + 10000), tx_ok_error_timer, NULL, txok_timer); DBG_ASSERT(txok_timer != NULL __DBG_LINE); #endif if (pbuf->attri.need_ack == TRUE) { tran_state.ack_needed = TRUE; } } else { hal_int_state_t s; HAL_ENTER_CRITICAL(s); if (ack_timer != NULL) { hal_timer_cancel(&ack_timer); } tran_send_failed(); HAL_EXIT_CRITICAL(s); } }
bool ScaledMatrix::HasValidNumbersImpl() const { DBG_ASSERT(IsValid(matrix_)); return matrix_->HasValidNumbers(); }
/*function uses to deal event when RX interrupt come*/ static void tran_deal_rxok_event(void) { sbuf_t *sbuf_tmp = NULL; bool_t is_valid_frm = FALSE; pbuf_t *pbuf = tran_state.cb.frm_get(); #if M_TRAN_DGB_EN > 0 m_tran_recv_tracker.rxok_msg_deal_tick = hal_timer_now().w; #endif if ((pbuf == NULL) || (pbuf->data_len == 0)) { if (pbuf != NULL) { pbuf_free(&pbuf __PLINE2); } return; } is_valid_frm = tran_state.cb.frm_head_parse(pbuf); if (is_valid_frm == TRUE) { /* 等待ACK时收到其他有效帧,释放该帧,继续等待 */ if ((tran_state.ack_needed == TRUE) && (pbuf->attri.is_ack == FALSE)) { pbuf_free(&pbuf __PLINE2); return; } #if M_TRAN_DGB_EN > 0 m_tran_tracker.recv_data++; #endif #if M_SYNC_EN > 0 m_sync_rxfilter(pbuf); #endif if (pbuf->attri.need_ack == TRUE) { tran_state.cb.send_ack(pbuf->attri.seq);//发送结束为IDLE状态 } else if (pbuf->attri.is_ack == TRUE) { #if M_TRAN_DGB_EN > 0 m_tran_tracker.recv_ack++; #endif if (tran_state.ack_needed == TRUE) //状态为正在等待ACK { if (tran_state.sbuf->primargs.pbuf->attri.seq == pbuf->attri.seq) { hal_int_state_t s; HAL_ENTER_CRITICAL(s); if (ack_timer != NULL) { hal_timer_cancel(&ack_timer); } else // 在处理ack期间等待ACK定时器已然触发,超时消息已发出 { if (tran_state.ack_timeout_happened) { //重传数据已经发出,TXOK消息已经发出,交给后面的TXOK消息处理 tran_state.ack_timeout_happened = FALSE; ack_timeout_cnt++; HAL_EXIT_CRITICAL(s); return; } else { ; // 超时消息处理在排队,本流程继续处理 } } tran_state.ack_needed = FALSE; tran_state.can_send = TRUE; tran_state.ack_received = TRUE; sbuf_tmp = tran_state.sbuf; tran_state.sbuf = NULL; HAL_EXIT_CRITICAL(s); #if M_TRAN_DGB_EN > 0 m_tran_tracker.tx_success_ack++; #endif DBG_ASSERT(tran_state.cb.tx_finish != NULL __DBG_LINE); tran_state.cb.tx_finish(sbuf_tmp, TRUE); } else { ; //收到错误的ACK } } else { ;//不处理不在等待ACK期间收到的ACK } } tran_state.cb.frm_payload_parse(pbuf); } else {// is valid == FALSE if(pbuf->used == TRUE) { pbuf_free(&pbuf __PLINE2); } phy_set_state(PHY_RX_STATE); } }
/*! \brief Wait until listener is ready to receive This function waits until a listener is ready. \param Pdx Pointer to the device extension. \param SendEoi TRUE if we want to signal an EOI. FALSE otherwise. */ VOID cbmiec_wait_for_listener(IN PDEVICE_EXTENSION Pdx, IN BOOLEAN SendEoi) { ULONG NumberOfAcks = SendEoi ? 2 : 1; FUNC_ENTER(); PERF_EVENT_VERBOSE(0x1100, NumberOfAcks); // This function has two incarnations. The first one // is used if we have successfully allocated the interrupt. // In this case, we just wait until the ISR has done the // essential work // When entering this function, DATA_IN should not be active DBG_ASSERT(CBMIEC_GET(PP_DATA_IN)); if (Pdx->ParallelPortAllocatedInterrupt) { LONG ret; // This is implementation 1. It needs a working // ISR. The main work is done there // Tell the ISR how many interrupts to wait for PERF_EVENT_VERBOSE(0x1101, NumberOfAcks); ret = InterlockedExchange(&Pdx->IrqCount, NumberOfAcks); DBG_ASSERT(ret==0); PERF_EVENT_VERBOSE(0x1102, ret); // in the sequel, allow interrupts to occur DBG_IRQ(("Allow Interrupts")); CBMIEC_SET(PP_LP_IRQ); /*! \todo Shouldn't we make sure that there * is no spurious interrupt until now? */ // Give the LISTENer the sign: We want to send something DBG_IRQ(("Release CLK_OUT")); CBMIEC_RELEASE(PP_CLK_OUT); #ifdef USE_DPC // set the cancel routine which will wake us up if we do not get // an IRQ, and a cancellation is requested PERF_EVENT_VERBOSE(0x1103, 0); DBG_VERIFY(IoSetCancelRoutine(Pdx->IrpQueue.CurrentIrp, WaitCancelRoutine) DBGDO(== NULL)); // Now, wait until we have been signalled PERF_EVENT_VERBOSE(0x1104, 0); DBG_DPC((DBG_PREFIX "CALL KeWaitForSingleObject()")); KeWaitForSingleObject(&Pdx->EventWaitForListener, Executive, KernelMode, FALSE, NULL); DBG_DPC((DBG_PREFIX "RETURN from KeWaitForSingleObject()")); PERF_EVENT_VERBOSE(0x1105, 0); // we do not need the cancel routine anymore: if (IoSetCancelRoutine(Pdx->IrpQueue.CurrentIrp, NULL) == NULL) { PERF_EVENT_VERBOSE(0x1106, -1); // the cancel routine was called! // Make sure the IrqCount is resetted to zero. InterlockedExchange(&Pdx->IrqCount, 0); } #else // Wait until the listener has told us that it is able to listen while (!QueueShouldCancelCurrentIrp(&Pdx->IrpQueue) && Pdx->IrqCount) { cbmiec_schedule_timeout(libiec_global_timeouts.T_WaitForListener_Granu_T_H); } #endif DBG_IRQ(("IrqCount = 0")); // from here on, no interrupts will be generated anymore CBMIEC_RELEASE(PP_LP_IRQ); DBG_IRQ(("No more Interrupts")); }
/*-------------------------------------------------------------------*/ ULONG CLI_CmdAutoRegist (const char *szCmd, //命令格式化串 USHORT ucMode, //命令所属模式 CLI_OPERAT_LEVEL_T ucLevel, //命令使用等级 PFUN_CLI_CALLBACK_EXEC pFunc, //命令执行函数 USHORT ucModeChange, //模式转换属性(非模式转换命令填CLI_MC_NULL) USHORT ucNewMode, //新模式的ID (仅当上一参数为CLI_MC_NEW时有意义 ) PCSTR strHelp1, //第一个对象的帮助信息 PCSTR strHelp2, //第二个对象的帮助信息 PCSTR strHelp3) { char szCmdString[CLI_MAX_CMD_FORMAT + 1]; /* 命令的表达式可以超过命令的实际长度256,暂定上限为1000*/ char szToken[CLI_MAX_CMDLEN]; char *pCurPos; ULONG ulRet, ulIndex = 0; PCSTR strObjHelp[CLI_MAX_KEY_NUM], strCheckID = NULL; USHORT ucIsNoForm = 0; PST_CLI_CMDKEY pCmdKey[CLI_MAX_KEY_NUM], pObj = NULL; PST_CLI_CMDKEY pFirstObj = NULL; ST_CLI_MODE *sMode; PST_CLI_PARAMLINK *pParamLink = NULL; CLI_ASSURE_OR_FAIL(szCmd != NULL && STB_StrLen(szCmd) > 0); /* DEBUG模式的命令只能在调试版本中存在 */ #if !CLI_DEBUG_ON if (ucMode == CTM_DBG) return TBS_SUCCESS; #endif STB_StrCpy(szCmdString, szCmd); (_VOID )_AffirmStrBeLower(szCmdString); /* 命令的注册语法检查 */ if (CLI_IsCmdValid(szCmdString) != TBS_SUCCESS) { REG_OUT("\r\n CLI: 命令格式不正确:%s",szCmd); DBG_ASSERT(0); return TBS_FAILED; } if (STB_StrNiCmp(szCmdString, "show ", 5) == 0) { ucMode = CTM_GLOBAL; } /* 其它参数合法性检查 */ if (ucMode >= MAX_MODE_NUM || ucNewMode >= MAX_MODE_NUM || ucLevel > CLI_AL_DEBUG) { REG_OUT("\r\n CLI: 注册命令存在不合法参数:mode-%d, new mode-%d, level-%d", ucMode, ucNewMode, ucLevel); DBG_ASSERT(0); return TBS_FAILED; } strObjHelp[0] = strHelp1; strObjHelp[1] = strHelp2; strObjHelp[2] = strHelp3; for (ulIndex = 0; ulIndex < 3; ulIndex++) { if (strObjHelp[ulIndex] != NULL) strCheckID = strObjHelp[ulIndex]; } if(!STB_StrNCmp(szCmdString, "show ", 5)) ucLevel = CLI_AL_QUERY; pCurPos = szCmdString; ulIndex = 0; /* 如果是否定形式的命令,则命令树中应该已经存在其肯定形式, 因此不用再创建对象,而采取搜索对象的形式 */ if (STB_StrNCmp("no ", pCurPos, 3) == 0) { ucIsNoForm = 1; pCurPos += 3; //跳过"no " if ((sMode = CLI_GetMode(ucMode)) == NULL) { REG_OUT("\r\n CLI: 该命令的肯定形式尚未注册 : %s", szCmd); DBG_ASSERT(0); return TBS_FAILED; } pObj = sMode->pCmdKey; /* 从模式对象开始搜索 */ } /* 注册对象 */ while((ulRet = CLI_GetObj(pCurPos, szToken)) != TBS_FAILED) { if (ulRet == TOKEN_GET_ONLYSPACE) { pCurPos++; continue; } if (ulRet == TOKEN_GET_CMDNULL) { REG_OUT("\r\n CLI: 从:%s 中获取命令字失败 : %s", pCurPos, szCmd); DBG_ASSERT(0); return TBS_FAILED; } pCurPos += STB_StrLen(szToken); /* 注册3个以上对象的命令不成功 */ if (ulIndex > 2) { REG_OUT("\r\n CLI: 关键命令字过多 : %s!", szCmd); DBG_ASSERT(0); return TBS_FAILED; } if (STB_StrLen(szToken) >= MAX_TOKEN_SIZE) { REG_OUT("\r\n CLI: 超长命令字注册 : %s!", szToken); DBG_ASSERT(0); return TBS_FAILED; } /* 肯定形式的对象自动注册 */ if (ucIsNoForm == 0) { if (ulRet == TOKEN_GET_LASTOBJ) { /* 最后一个命令对象需要处理其操作方法: 回调函数或模式转换 */ switch (ucModeChange) { case CLI_MC_NULL: /* 对于非模式转换的命令需要保证带回调函数 */ if (pFunc == NULL) { REG_OUT("\r\n CLI: 命令(%s)\r\n 的对象(%s)没有执行操作!", szCmd, szToken); DBG_ASSERT(0); return TBS_FAILED; } pCmdKey[ulIndex] = CLI_CreateObject(szToken, ucMode, ucLevel, pFunc, FALSE, CLI_MC_NULL, NULL); break; /* 以下是对各种模式转换类型的对象注册 */ case CLI_MC_END: pCmdKey[ulIndex] = CLI_CreateObject(szToken, ucMode, ucLevel, pFunc, TRUE, CLI_MC_END, NULL); break; case CLI_MC_EXIT: pCmdKey[ulIndex] = CLI_CreateObject(szToken, ucMode, ucLevel, pFunc, TRUE, CLI_MC_EXIT, NULL); break; case CLI_MC_NEW: /* 如果是转换到新模式,需要保证新模式的正确性 */ if (ucNewMode == NULL_MODE) { REG_OUT("\r\n CLI: 模式转换命令注册错误: 新模式ID: %d", ucNewMode); DBG_ASSERT(0); return TBS_FAILED; } pCmdKey[ulIndex] = CLI_CreateObject(szToken, ucMode, ucLevel, pFunc, TRUE, CLI_MC_NEW, NULL); /* 如果是转换到新模式,还需要将该对象注册为新模式的模式对象*/ if (*pCurPos == ':' || *(pCurPos + 1) == ':') /*这里需要改进*/ CLI_RegModeObject(ucNewMode, pCmdKey[ulIndex], 2); else CLI_RegModeObject(ucNewMode, pCmdKey[ulIndex], 0); break; default: DBG_ASSERT(0); return TBS_FAILED; } pParamLink = &(pCmdKey[ulIndex]->action.pParamLink); } else { pCmdKey[ulIndex] = CLI_CreateObject(szToken, ucMode, ucLevel, NULL, FALSE, CLI_MC_NULL, NULL); } if (pCmdKey[ulIndex] == NULL) { REG_OUT("\r\n CLI: 对象创建失败: %s", szCmd); DBG_ASSERT(0); return TBS_FAILED; } if (ulIndex == 0) { pFirstObj = pCmdKey[ulIndex]; } else { CLI_RegObject(pCmdKey[ulIndex - 1], pCmdKey[ulIndex]); } if (ucMode != CTM_DBG && ucMode != CTM_DIAG) { if (strObjHelp[ulIndex] == CLI_ML_NULL) { REG_OUT("\r\n CLI: 命令(%s)\r\n 的对象(%s) 缺少帮助信息!", szCmd, szToken); DBG_ASSERT(0); return TBS_FAILED; } if (((CLI_IsObjectExecutable(pCmdKey[ulIndex], HAVEACTIONS) == TBS_SUCCESS) && (strstr(strObjHelp[ulIndex], HELP_FUN) == NULL)) || ((CLI_IsObjectExecutable(pCmdKey[ulIndex], HAVEACTIONS) != TBS_SUCCESS) && strstr(strObjHelp[ulIndex], HELP_FUN) != NULL)) { if (STB_StriCmp(szToken, "cm")) { REG_OUT("\r\n CLI: 命令(%s)\r\n 的对象(%s) 帮助信息格式不正确!", szCmd, szToken); DBG_ASSERT(0); return TBS_FAILED; } } } CLI_RegCmdHelp(pCmdKey[ulIndex], strObjHelp[ulIndex]); } /* 否定形式的命令注册: 自动查找肯定形式的命令并修改其属性 */ /* 使之具有命令的否定形式 */ else { if (ulRet == TOKEN_GET_LASTOBJ) { pObj = CLI_GetSubObjByName(pObj, szToken); if (pObj == NULL) { REG_OUT("\r\n CLI: 该命令的肯定形式尚未注册 : %s", szCmd); DBG_ASSERT(0); return TBS_FAILED; } pParamLink = &(pObj->noAction.pParamLink); /* 设置该对象的否定属性 */ pObj->noAction.ulMode = pObj->action.ulMode; pObj->noAction.rightLevel = pObj->action.rightLevel; pObj->noAction.pFunction = pFunc; pObj->ulNoFlag = 1; } else { pObj = CLI_GetSubObjByName(pObj, szToken); if (pObj == NULL) { REG_OUT("\r\n CLI: 该命令的肯定形式尚未注册 : %s", szCmd); DBG_ASSERT(0); return TBS_FAILED; } pObj->ulNoFlag = 1; } } ulIndex++; /* 如果已经是最后一个对象,则跳出循环 */ if (ulRet == TOKEN_GET_LASTOBJ) break; } /* 注册命令到模式必须要在所有对象创建完成之后进行, */ /* 否则无法注册具有相同对象的情况 */ if (ucIsNoForm == 0) { if (CLI_RegObjToMode(ucMode, pFirstObj)) { REG_OUT( "\r\n CLI: 命令注册失败: %s", szCmd); DBG_ASSERT(0); } } while (*pCurPos == KEY_SPACE) pCurPos++; if (*pCurPos != ':') { return TBS_SUCCESS; } while (*(++pCurPos) == KEY_SPACE) ; /* 这种情况表示分隔符后面已经没有参数链,直接返回 */ if (*pCurPos == '\0') { return TBS_SUCCESS; } if (pParamLink == NULL) /* 此判断不会进来,消除pc-lint告警 */ { MT_ERRLOG(0); return TBS_FAILED; } /*注册参数与参数值*/ *pParamLink = CLI_CreatGroup(pCurPos); if (*pParamLink == NULL) { REG_OUT("\r\n CLI: 命令(%s)参数群注册失败!", szCmd); DBG_ASSERT(0); return TBS_FAILED; } return TBS_SUCCESS; }
inet_err_t recv_max_len_set(size_t recv_max_len) throw() { DBG_ASSERT(tcp_full); return tcp_full->recv_max_len_set(recv_max_len); }
bool RestoIterateInitializer::SetInitialIterates() { DBG_START_METH("RestoIterateInitializer::SetInitialIterates", dbg_verbosity); // Get a grip on the restoration phase NLP and obtain the pointers // to the original NLP data SmartPtr<RestoIpoptNLP> resto_ip_nlp = static_cast<RestoIpoptNLP*> (&IpNLP()); SmartPtr<IpoptNLP> orig_ip_nlp = static_cast<IpoptNLP*> (&resto_ip_nlp->OrigIpNLP()); SmartPtr<IpoptData> orig_ip_data = static_cast<IpoptData*> (&resto_ip_nlp->OrigIpData()); SmartPtr<IpoptCalculatedQuantities> orig_ip_cq = static_cast<IpoptCalculatedQuantities*> (&resto_ip_nlp->OrigIpCq()); // Set the value of the barrier parameter Number resto_mu; resto_mu = Max(orig_ip_data->curr_mu(), orig_ip_cq->curr_c()->Amax(), orig_ip_cq->curr_d_minus_s()->Amax()); IpData().Set_mu(resto_mu); Jnlst().Printf(J_DETAILED, J_INITIALIZATION, "Initial barrier parameter resto_mu = %e\n", resto_mu); ///////////////////////////////////////////////////////////////////// // Initialize primal varialbes // ///////////////////////////////////////////////////////////////////// // initialize the data structures in the restoration phase NLP IpData().InitializeDataStructures(IpNLP(), false, false, false, false, false); SmartPtr<Vector> new_x = IpData().curr()->x()->MakeNew(); SmartPtr<CompoundVector> Cnew_x = static_cast<CompoundVector*> (GetRawPtr(new_x)); // Set the trial x variables from the original NLP Cnew_x->GetCompNonConst(0)->Copy(*orig_ip_data->curr()->x()); // Compute the initial values for the n and p variables for the // equality constraints Number rho = resto_ip_nlp->Rho(); DBG_PRINT((1,"rho = %e\n", rho)); SmartPtr<Vector> nc = Cnew_x->GetCompNonConst(1); SmartPtr<Vector> pc = Cnew_x->GetCompNonConst(2); SmartPtr<const Vector> cvec = orig_ip_cq->curr_c(); DBG_PRINT_VECTOR(2, "cvec", *cvec); SmartPtr<Vector> a = nc->MakeNew(); SmartPtr<Vector> b = nc->MakeNew(); a->Set(resto_mu/(2.*rho)); a->Axpy(-0.5, *cvec); b->Copy(*cvec); b->Scal(resto_mu/(2.*rho)); DBG_PRINT_VECTOR(2, "a", *a); DBG_PRINT_VECTOR(2, "b", *b); solve_quadratic(*a, *b, *nc); pc->Copy(*cvec); pc->Axpy(1., *nc); DBG_PRINT_VECTOR(2, "nc", *nc); DBG_PRINT_VECTOR(2, "pc", *pc); // initial values for the n and p variables for the inequality // constraints SmartPtr<Vector> nd = Cnew_x->GetCompNonConst(3); SmartPtr<Vector> pd = Cnew_x->GetCompNonConst(4); cvec = orig_ip_cq->curr_d_minus_s(); a = nd->MakeNew(); b = nd->MakeNew(); a->Set(resto_mu/(2.*rho)); a->Axpy(-0.5, *cvec); b->Copy(*cvec); b->Scal(resto_mu/(2.*rho)); solve_quadratic(*a, *b, *nd); pd->Copy(*cvec); pd->Axpy(1., *nd); DBG_PRINT_VECTOR(2, "nd", *nd); DBG_PRINT_VECTOR(2, "pd", *pd); // Leave the slacks unchanged SmartPtr<const Vector> new_s = orig_ip_data->curr()->s(); // Now set the primal trial variables DBG_PRINT_VECTOR(2,"new_s",*new_s); DBG_PRINT_VECTOR(2,"new_x",*new_x); SmartPtr<IteratesVector> trial = IpData().curr()->MakeNewContainer(); trial->Set_primal(*new_x, *new_s); IpData().set_trial(trial); DBG_PRINT_VECTOR(2, "resto_c", *IpCq().trial_c()); DBG_PRINT_VECTOR(2, "resto_d_minus_s", *IpCq().trial_d_minus_s()); ///////////////////////////////////////////////////////////////////// // Initialize bound multipliers // ///////////////////////////////////////////////////////////////////// SmartPtr<Vector> new_z_L = IpData().curr()->z_L()->MakeNew(); SmartPtr<CompoundVector> Cnew_z_L = static_cast<CompoundVector*> (GetRawPtr(new_z_L)); DBG_ASSERT(IsValid(Cnew_z_L)); SmartPtr<Vector> new_z_U = IpData().curr()->z_U()->MakeNew(); SmartPtr<Vector> new_v_L = IpData().curr()->v_L()->MakeNew(); SmartPtr<Vector> new_v_U = IpData().curr()->v_U()->MakeNew(); // multipliers for the original bounds are SmartPtr<const Vector> orig_z_L = orig_ip_data->curr()->z_L(); SmartPtr<const Vector> orig_z_U = orig_ip_data->curr()->z_U(); SmartPtr<const Vector> orig_v_L = orig_ip_data->curr()->v_L(); SmartPtr<const Vector> orig_v_U = orig_ip_data->curr()->v_U(); // Set the new multipliers to the min of the penalty parameter Rho // and their current value SmartPtr<Vector> Cnew_z_L0 = Cnew_z_L->GetCompNonConst(0); Cnew_z_L0->Set(rho); Cnew_z_L0->ElementWiseMin(*orig_z_L); new_z_U->Set(rho); new_z_U->ElementWiseMin(*orig_z_U); new_v_L->Set(rho); new_v_L->ElementWiseMin(*orig_v_L); new_v_U->Set(rho); new_v_U->ElementWiseMin(*orig_v_U); // Set the multipliers for the p and n bounds to the "primal" multipliers SmartPtr<Vector> Cnew_z_L1 = Cnew_z_L->GetCompNonConst(1); Cnew_z_L1->Set(resto_mu); Cnew_z_L1->ElementWiseDivide(*nc); SmartPtr<Vector> Cnew_z_L2 = Cnew_z_L->GetCompNonConst(2); Cnew_z_L2->Set(resto_mu); Cnew_z_L2->ElementWiseDivide(*pc); SmartPtr<Vector> Cnew_z_L3 = Cnew_z_L->GetCompNonConst(3); Cnew_z_L3->Set(resto_mu); Cnew_z_L3->ElementWiseDivide(*nd); SmartPtr<Vector> Cnew_z_L4 = Cnew_z_L->GetCompNonConst(4); Cnew_z_L4->Set(resto_mu); Cnew_z_L4->ElementWiseDivide(*pd); // Set those initial values to be the trial values in Data trial = IpData().trial()->MakeNewContainer(); trial->Set_bound_mult(*new_z_L, *new_z_U, *new_v_L, *new_v_U); IpData().set_trial(trial); ///////////////////////////////////////////////////////////////////// // Initialize equality constraint multipliers // ///////////////////////////////////////////////////////////////////// DefaultIterateInitializer::least_square_mults( Jnlst(), IpNLP(), IpData(), IpCq(), resto_eq_mult_calculator_, constr_mult_init_max_); // upgrade the trial to the current point IpData().AcceptTrialPoint(); DBG_PRINT_VECTOR(2, "y_c", *IpData().curr()->y_c()); DBG_PRINT_VECTOR(2, "y_d", *IpData().curr()->y_d()); DBG_PRINT_VECTOR(2, "z_L", *IpData().curr()->z_L()); DBG_PRINT_VECTOR(2, "z_U", *IpData().curr()->z_U()); DBG_PRINT_VECTOR(2, "v_L", *IpData().curr()->v_L()); DBG_PRINT_VECTOR(2, "v_U", *IpData().curr()->v_U()); return true; }