Exemplo n.º 1
0
void reset(int arg) {
  if(arg) return;

  set_light(1);
  add_property("hills");

  set_short("Rolling Hills");
  set_long(LB("You stand on the edge of a great land of rolling hills.  "+
	"A wide track winds its way through here, heading south back to "+
	"the lands of men.  The hum of insects is heard in the air, lending "+
	"a natural feel to this otherwise quiet land.  The hills seem "+
	"empty, and a light mist shrouds the distance."));
  add_item("insects", LB("The sound of crickets and cicadas give the "+
	"only signs of activity here."));
  add_item("hills", LB("The hills that surround you are quiet and "+
	"apparently largely uninhabited, except for insects and small "+
	"animals.  The skies are strangely empty of avians, and you "+
	"see no man-made structures around you.  You intuit an unexplained "+
	"spookiness in this forlorn place, however."));
  add_item("track", LB("The dirt track leads back to the village to the "+
	"south.  It is the only safe road into this land, and thus the "+
	"most travelled, but that is only relative."));
  add_item("mist", LB("The mist, which only obscures the distances, "+
	"lends to the loneliness of the land."));
  add_exit("north","hill2");
  add_exit("west", "hill4");
  add_exit("south","track3");
}
Exemplo n.º 2
0
Arquivo: net.c Projeto: avagin/linux
static int skb_to_mamac(const struct sk_buff *skb, struct mbo *mbo)
{
	u8 *buff = mbo->virt_address;
	static const u8 broadcast[] = { 0x03, 0xFF };
	const u8 *dest_addr = skb->data + 4;
	const u8 *eth_type = skb->data + 12;
	unsigned int payload_len = skb->len - ETH_HLEN;
	unsigned int mdp_len = payload_len + MDP_HDR_LEN;

	if (mbo->buffer_length < mdp_len) {
		pr_err("drop: too small buffer! (%d for %d)\n",
		       mbo->buffer_length, mdp_len);
		return -EINVAL;
	}

	if (skb->len < ETH_HLEN) {
		pr_err("drop: too small packet! (%d)\n", skb->len);
		return -EINVAL;
	}

	if (dest_addr[0] == 0xFF && dest_addr[1] == 0xFF)
		dest_addr = broadcast;

	*buff++ = HB(mdp_len - 2);
	*buff++ = LB(mdp_len - 2);

	*buff++ = PMHL;
	*buff++ = (PMS_FIFONO_MDP << PMS_FIFONO_SHIFT) | PMS_MSGTYPE_DATA;
	*buff++ = PMS_DEF_PRIO;
	*buff++ = dest_addr[0];
	*buff++ = dest_addr[1];
	*buff++ = 0x00;

	*buff++ = HB(payload_len + 6);
	*buff++ = LB(payload_len + 6);

	/* end of FPH here */

	*buff++ = eth_type[0];
	*buff++ = eth_type[1];
	*buff++ = 0;
	*buff++ = 0;

	*buff++ = PMS_TELID_UNSEGM_MAMAC << 4 | HB(payload_len);
	*buff++ = LB(payload_len);

	memcpy(buff, skb->data + ETH_HLEN, payload_len);
	mbo->buffer_length = mdp_len;
	return 0;
}
Exemplo n.º 3
0
int main(int argc, char * argv[])
{
	try
	{
		libmaus::util::ArgInfo const arginfo(argc,argv);
		char const * a = 0;
		char const * e = 0;
		
		if ( arginfo.restargs.size() )
		{
			for ( uint64_t i = 0; i < arginfo.restargs.size(); ++i )
			{
				std::string const fn = arginfo.restargs.at(i);
				libmaus::aio::CheckedInputStream CIS1(fn);
				libmaus::aio::CheckedInputStream CIS2(fn);
				libmaus::util::LineBuffer LB(CIS1);
				
				while ( LB.getline(&a,&e) )
				{
					std::string const line(a,e);
					std::string refline;
					std::getline(CIS2,refline);
					
					if ( line != refline )
					{
						std::cerr << line << "\n!=\n" << refline << "\n";
						return EXIT_FAILURE;
					}
				}
				
				std::cerr << "check for " << fn << " ok" << std::endl;
			}
		}
		else
		{
			libmaus::util::LineBuffer LB(std::cin,64*1024);
			
			while ( LB.getline(&a,&e) )
			{
				std::cout.write(a,e-a);
				std::cout.put('\n');
			}
		}
	}
	catch(std::exception const & ex)
	{
		std::cerr << ex.what() << std::endl;
		return EXIT_FAILURE;	
	}
}
Exemplo n.º 4
0
void packet_sum(){

	short x = (X_SIGN(packet[0]) ? (packet[1] | (0xff << 8)) : packet[1]);
	short y = (Y_SIGN(packet[0]) ? (packet[2] | (0xff << 8)) : packet[2]);
	if(LB(packet[0])){
		X += x;
		Y += y;
		printf("X:%d	Y:%d	LB:%d \n",X,Y,LB(packet[0]));
	}
	else{
		X=0;
		Y=0;
		printf("LB:%d \n",LB(packet[0]));
	}
	counter = 0;
}
Exemplo n.º 5
0
int CCMinFinder::FindMinimum(byte Meth)
{
    int Ret=-1;
    switch (Meth)
    {
    case CMM_None:
        ;
        break;
    case CMM_Controls:
    {
        CMFControls *p=new CMFControls(this);
        Ret=p->Solve();
        delete p;
        //CMFControls Cn(this);
        //Ret=Cn.Solve();
        break;
    };
    case CMM_LawBailey:
    {
        CMFLawBailey LB(this);
        Ret=LB.Solve();
        break;
    };
    case CMM_FlexiPlex:
    {
        //CMFFlexiPlex *p=new CMFFlexiPlex(this);
        //Ret=p->Solve();
        //delete p;
        CMFFlexiPlex FP(this);
        Ret=FP.Solve();
        break;
    };
    };
    return Ret;
};
Exemplo n.º 6
0
/** Get the ith token from the current position 1..n where k=1 is the
*  first symbol of lookahead.
*/
static pANTLR3_COMMON_TOKEN 
tokLT  (pANTLR3_TOKEN_STREAM ts, ANTLR3_INT32 k)
{
	ANTLR3_INT32    i;
	ANTLR3_INT32    n;
	pANTLR3_COMMON_TOKEN_STREAM cts;

	cts	    = (pANTLR3_COMMON_TOKEN_STREAM)ts->super;

        if	(k < 0)
	{
		return LB(cts, -k);
	}

	if	(cts->p == -1)
	{
		fillBuffer(cts);
	}

        // Here we used to check for k == 0 and return 0, but this seems
        // a superfluous check to me. LT(k=0) is therefore just undefined
        // and we won't waste the clock cycles on the check
        //

	if	((cts->p + k - 1) >= (ANTLR3_INT32)ts->istream->cachedSize)
	{
		pANTLR3_COMMON_TOKEN    teof = &(ts->tokenSource->eofToken);

		teof->setStartIndex (teof, ts->istream->index	    (ts->istream));
		teof->setStopIndex  (teof, ts->istream->index	    (ts->istream));
		return  teof;
	}

	i	= cts->p;
	n	= 1;

	/* Need to find k good tokens, skipping ones that are off channel
	*/
	while   ( n < k)
	{
		/* Skip off-channel tokens */
		i = skipOffTokenChannels(cts, i+1); /* leave p on valid token    */
		n++;
	}
	if	( (ANTLR3_UINT32) i >= ts->istream->cachedSize)
	{
		pANTLR3_COMMON_TOKEN    teof = &(ts->tokenSource->eofToken);

		teof->setStartIndex (teof, ts->istream->index(ts->istream));
		teof->setStopIndex  (teof, ts->istream->index(ts->istream));
		return  teof;
	}

	// Here the token must be in the input vector. Rather then incur
	// function call penalty, we just return the pointer directly
	// from the vector
	//
	return  (pANTLR3_COMMON_TOKEN)cts->tokens->elements[i].element;
	//return  (pANTLR3_COMMON_TOKEN)cts->tokens->get(cts->tokens, i);
}
Exemplo n.º 7
0
Arquivo: net.c Projeto: avagin/linux
static int skb_to_mep(const struct sk_buff *skb, struct mbo *mbo)
{
	u8 *buff = mbo->virt_address;
	unsigned int mep_len = skb->len + MEP_HDR_LEN;

	if (mbo->buffer_length < mep_len) {
		pr_err("drop: too small buffer! (%d for %d)\n",
		       mbo->buffer_length, mep_len);
		return -EINVAL;
	}

	*buff++ = HB(mep_len - 2);
	*buff++ = LB(mep_len - 2);

	*buff++ = PMHL;
	*buff++ = (PMS_FIFONO_MEP << PMS_FIFONO_SHIFT) | PMS_MSGTYPE_DATA;
	*buff++ = (MEP_DEF_RETRY << PMS_RETRY_SHIFT) | PMS_DEF_PRIO;
	*buff++ = 0;
	*buff++ = 0;
	*buff++ = 0;

	memcpy(buff, skb->data, skb->len);
	mbo->buffer_length = mep_len;
	return 0;
}
/// Get tree node at current input pointer + i ahead where i=1 is next node.
/// i<0 indicates nodes in the past.  So -1 is previous node and -2 is
/// two nodes ago. LT(0) is undefined.  For i>=n, return null.
/// Return null for LT(0) and any index that results in an absolute address
/// that is negative.
///
/// This is analogous to the _LT() method of the TokenStream, but this
/// returns a tree node instead of a token.  Makes code gen identical
/// for both parser and tree grammars. :)
///
static  pANTLR3_BASE_TREE
_LT         (pANTLR3_TREE_NODE_STREAM tns, ANTLR3_INT32 k)
{
        if      (tns->ctns->p == -1)
        {
                fillBufferRoot(tns->ctns);
        }

        if      (k < 0)
        {
                return LB(tns, -k);
        }
        else if (k == 0)
        {
                return  &(tns->ctns->INVALID_NODE.baseTree);
        }

        // k was a legitimate request,
        //
        if      (( tns->ctns->p + k - 1) >= (ANTLR3_INT32)(tns->ctns->nodes->count))
        {
                return &(tns->ctns->EOF_NODE.baseTree);
        }

        return  tns->ctns->nodes->get(tns->ctns->nodes, tns->ctns->p + k - 1);
}
Exemplo n.º 9
0
/** Get the ith token from the current position 1..n where k=1 is the
*  first symbol of lookahead.
*/
static pANTLR3_COMMON_TOKEN 
tokLT  (pANTLR3_TOKEN_STREAM ts, ANTLR3_INT32 k)
{
	ANTLR3_INT32    i;
	ANTLR3_INT32    n;
	pANTLR3_COMMON_TOKEN_STREAM cts;

	cts	    = (pANTLR3_COMMON_TOKEN_STREAM)ts->super;


	if	(cts->p == -1)
	{
		fillBuffer(cts);
	}
	if	(k == 0)
	{
		return NULL;
	}
	if	(k < 0)
	{
		return LB(cts, -k);
	}

	if	((cts->p + k - 1) >= (ANTLR3_INT32)ts->istream->cachedSize)
	{
		pANTLR3_COMMON_TOKEN    teof = &(ts->tokenSource->eofToken);

		teof->setStartIndex (teof, ts->istream->index	    (ts->istream));
		teof->setStopIndex  (teof, ts->istream->index	    (ts->istream));
		return  teof;
	}

	i	= cts->p;
	n	= 1;

	/* Need to find k good tokens, skipping ones that are off channel
	*/
	while   ( n < k)
	{
		/* Skip off-channel tokens */
		i = skipOffTokenChannels(cts, i+1); /* leave p on valid token    */
		n++;
	}
	if	( (ANTLR3_UINT32) i > ts->istream->cachedSize)
	{
		pANTLR3_COMMON_TOKEN    teof = &(ts->tokenSource->eofToken);

		teof->setStartIndex (teof, ts->istream->index(ts->istream));
		teof->setStopIndex  (teof, ts->istream->index(ts->istream));
		return  teof;
	}

	// Here the token must be in the input vector. Rather then incut
	// function call penalty, we jsut return the pointer directly
	// from the vector
	//
	return  (pANTLR3_COMMON_TOKEN)cts->tokens->elements[i].element;
	//return  (pANTLR3_COMMON_TOKEN)cts->tokens->get(cts->tokens, i);
}
Exemplo n.º 10
0
void packet_print(){
	short x = (X_SIGN(packet[0]) ? (packet[1] | (0xff << 8)) : packet[1]);
	short y = (Y_SIGN(packet[0]) ? (packet[2] | (0xff << 8)) : packet[2]);
	printf("B1=0x%x B2=0x%x B3=0x%x LB=%d MB=%d RB=%d XOV=%d YOV=%d X=%d Y=%d \n",
			packet[0], packet[1], packet[2],
			LB(packet[0]), MB(packet[0]), RB(packet[0]),
			X_OVF(packet[0]), Y_OVF(packet[0]),
			x, y);
	counter = 0;
}
Exemplo n.º 11
0
    vector<Point2F> Square::GetCorners() const {
        vector<Point2F> v;
        v.reserve(4);

        v.push_back(LT());
        v.push_back(LB());
        v.push_back(RT());
        v.push_back(RB());

        return v;
    }
Exemplo n.º 12
0
void cpu_reset(void)
{
	union reg acc;
#ifdef DYNAREC
        int i;
        dynapointer=0;
#endif
	cpu.speed = 0;
	cpu.halt = 0;
	cpu.div = 0;
	cpu.tim = 0;
	cpu.lcdc = 40;

	IME = 0;
	IMA = 0;
	
	PC = 0x0100;
	SP = 0xFFFE;
	W(acc) = 0x01B0;
	A=HB(acc);
	F=LB(acc);
	W(acc) = 0x0013;
	B=HB(acc);
	C=LB(acc);
	W(acc) = 0x00D8;
	D=HB(acc);
	E=LB(acc);
	HL = 0x014D;

        if (hw.cgb) A = 0x11;
        if (hw.gba) B = 0x01;
#ifdef DYNAREC
        for(i=0;i<(1<<HASH_SIGNIFICANT_LOWER_BITS);i++)
           address_map[i]=0;
#endif
}
Exemplo n.º 13
0
void RigidBody::update(real_t dt)
{
	//momentum and position is updated in the same way as in MaterialBody
	Parent::update(dt);

	//update angular momentum
	setLB(LA() + resultantMoment() * dt);
	//update angle
	real_t angleB = angleA() + LB() / I() * dt;
	if (angleB > 2 * math::PI)
		angleB -= 2 * math::PI;
	else if (angleB < -2 * math::PI)
		angleB += 2 * math::PI;
	setAngleB(angleB);
}
Exemplo n.º 14
0
extern void serial_init () 
{
  /* disable interrupts */
  OUTB(0x0,COM1+1); 
  /* enable dlab (baud rate divisor) */
  OUTB(0x80,COM1+3);
  /* set divisor */
  u16 div = get_divisor ();
  OUTB(LB(div),COM1+0); 
  OUTB(HB(div),COM1+1);
  /* 8 bits, no parity, one stop byte */
  OUTB(0x03,COM1+3); 
  /* fifo 14-byte threshold */
  OUTB(0xc7,COM1+2);
  /* irqs enabled */
  OUTB(0x0b,COM1+4);
}
Exemplo n.º 15
0
int test_config(void) {
	unsigned long byte;
	subscribe_mouse();
	mouse_write_byte(DISABLE_DATA_PACKETS);
	mouse_write_byte(STATUS_REQUEST);
	byte = mouse_read();
	if(byte == -1) return 1;
	printf("byte 1: 0x%X\n", byte);
	printf("Scaling: ");
	if(!SCALING(byte))
		printf("1:1  ");
	else
		printf("2:1  ");
	printf("Data Reporting: ");
	if(!DATA_REPORTING(byte))
		printf("disable  ");
	else
		printf("enable   ");
	printf("Mode: ");
	if(!MODE(byte))
		printf("remote mode\n\n");
	else
		printf("stream mode\n\n");
	if(LB(byte))
		printf("LB: pressed ");
	else
		printf("LB: not pressed ");
	if(RB(byte))
		printf("RB: pressed ");
	else
		printf("RB: not pressed ");
	if(MB(byte))
		printf("MB: pressed ");
	else
		printf("MB: not pressed ");
	byte = mouse_read();
	if(byte == -1) return 1;
	printf("\n byte 2: 0x%X\n", byte);
	printf("Resolution: %d\n\n", byte);
	byte = mouse_read();
	if(byte == -1) return 1;
	printf("byte 3: 0x%X\n", byte);
	printf("Sample Rate: %d\n\n", byte);
}
Exemplo n.º 16
0
void reset(int arg) {
  if(arg) return;

  set_light(1);
  add_property("hills");
  add_property("water");

  set_short("Rolling Hills Near River");
  set_long(LB("Here the hills flatten out and slope down to the edge "+
	"of a river to the west.  The river is slow-moving, and is shallow "+
	"enough at this point for you to ford.  Beyond the river you "+
	"catch sight of the open plains.  To the east is a dark and ancient "+
	"wood."));

  add_item("wood", LB("The small forest in the centre of the plains is "+
	"the Old Wood, said in folklore to be one of a few remnants of a "+
	"great forest which covered the whole of Nanny in millenia past, "+
	"before the coming of humans.  It is a dark and mysterious place, "+
	"where ancient powers sleep and dream of their past might."));
  add_item("river", LB("The river flows down from the mountains to the "+
	"north.  It is wide and its waters are ice-cold, and here is one "+
	"of the few places where you may cross it safely."));
  add_item("mountains", LB("Off in the distance to the north are the "+
	"tall and craggly mountains which shadow these lands.  It is "+
	"said that a great pine forest lies beyond them, where men "+
	"and dragons live peacefully, where wealth is abundant, and "+
	"evil does not exist.")); /* Not true, this rumour :) */
  add_item("hills", LB("The hills that surround you are quiet and "+
	"apparently largely uninhabited, except for insects and small "+
	"animals.  The skies are strangely empty of avians, and you "+
	"see no man-made structures around you.  You intuit an unexplained "+
	"spookiness in this forlorn place, however."));
  add_item("mist", LB("The mist, which only obscures the distances, "+
	"lends to the loneliness of the land."));

  add_exit("north","hill8");
  add_exit("east", "old_wood");
  add_exit("south","hill6");
  add_exit("west", "ford");

  add_command("drink %s","@drink_verb()");
}
Exemplo n.º 17
0
double SVM::train()
{
	Array X(input, nInstances, nVars);
	Array y(response, nInstances);
	Array K;
	
	if(opt->kernel == SVM_RBF)
	{
		K = kernelRBF(X, X, opt->sigma);
	}
	else if(opt->kernel == SVM_LINEAR)
	{
		K = kernelLinear(X, X);
	}
	else{
		exit(-1);
	}
	
	// K must be a symmetric matrix
	assert(K.rows == K.cols);
	
	double *_K = K.getData();

	Array A(K.rows, K.cols);
	double *_A = A.getData();
	double *_y = y.getData();
	
	int step = A.cols;
	for(int i = 0;i < K.rows; i++)
	{
		for(int j = 0;j < K.cols;j++)
			_A[i * step + j] = _y[i] * _y[j] * _K[i * step + j];
	}	
	
	Array LB(nInstances);
	Array UB(nInstances);
	
	double *_LB = LB.getData();
	double *_UB = UB.getData();
	
	for(int i = 0;i < UB.size;i++)
		_UB[i] = opt->C;
		
	for(int i = 0;i < LB.size;i++)
		_LB[i] = 0;

	Array x(nInstances);
	x.setZeros();
	
#ifdef DEBUG
	opt->minconf_opt.verbose = 3;
#endif

	minConf_TMP trainer(x, LB, UB, &(opt->minconf_opt));
	trainer.loadData(nInstances, nInstances, _A, _y);
	trainer.process();
	
	trainErr = getTrainErr(x, y, K);
	
	alpha = x.getData();
	
	// Release memory.
	A.release();
	K.release();
	LB.release();
	UB.release();
	
	return trainErr;
}
Exemplo n.º 18
0
void add(int w,int d){
	for(;w<=N;w+=LB(w))tree[w]+=d;
	} 
Exemplo n.º 19
0
int main(int argc, char *argv[])
{
	try
	{
		libmaus2::util::ArgParser const arg(argc,argv);

		libmaus2::util::LineBuffer LB(std::cin);
		char const * a;
		char const * e;

		std::ostringstream headerostr;
		bool haveheader = false;
		libmaus2::bambam::BamHeader::unique_ptr_type Pheader;
		libmaus2::bambam::SamInfo::unique_ptr_type Pinfo;

		while ( LB.getline(&a,&e) )
		{
			if ( e-a && a[0] == '@' )
			{
				if ( ! haveheader )
				{
					headerostr << std::string(a,e) << "\n";
				}
				else
				{
					libmaus2::exception::LibMausException lme;
					lme.getStream() << "[E] header line in data part" << std::endl;
					lme.finish();
					throw lme;
				}
			}
			else if ( e-a )
			{
				if ( ! Pinfo )
				{
					libmaus2::bambam::BamHeader::unique_ptr_type Theader(new libmaus2::bambam::BamHeader(headerostr.str()));
					Pheader = UNIQUE_PTR_MOVE(Theader);
					libmaus2::bambam::SamInfo::unique_ptr_type Tinfo(new libmaus2::bambam::SamInfo(*Pheader));
					Pinfo = UNIQUE_PTR_MOVE(Tinfo);

					std::cout << headerostr.str();
				}

				try
				{
					Pinfo->parseSamLine(a,e);

					if ( Pinfo->algn.isMapped() )
					{
						if (
							static_cast<int64_t>(Pinfo->algn.getPos() + Pinfo->algn.getReferenceLength()) >
							static_cast<int64_t>(Pheader->getRefIDLength(Pinfo->algn.getRefID()))
						)
						{
							libmaus2::exception::LibMausException lme;
							lme.getStream() << "[E] alignment extends past end of reference sequence" << std::endl;
							lme.finish();
							throw lme;
						}
					}

					std::cout << std::string(a,e) << "\n";
				}
				catch(std::exception const & ex)
				{
					std::cerr << ex.what() << std::endl;
				}
			}
		}
	}
	catch(std::exception const & ex)
	{
		std::cerr << ex.what() << std::endl;
	}
}
Exemplo n.º 20
0
	LL query(int w) {
		LL ret = 0;
		for (w += 3; w > 0; w -= LB(w))ret += _[w];
		return ret;
	}
Exemplo n.º 21
0
	void update(int w, LL d) {
		for (w += 3; w < n; w += LB(w))_[w] += d;
	}
Exemplo n.º 22
0
Arquivo: main.c Projeto: oldjohnh/car
int main(void)
{

	SystemClockSetup(ClockSource_EX50M,CoreClock_100M);
	DelayInit();
	OLED_Init();
	Sd_Init();
	chuinit_Init();
	DataInit();
	Data_Uart_Init();
	
	while(1)
	{
		Menu_Init();
		//ccd
		while(Flag == 1)
		{
			if(TIME1flag_20ms == 1)
			{
				TIME1flag_20ms = 0;
				ImageCapture(Pixel);
//				Sd_X();
//				Sd_D();
//				UART_Send_Con();
				erzhi();
				LB();
				oled_collect();
				oled_show();
			}
			CCD_HeiXian();
			OLED_ZhongXian();
			OLED_Write_Num3(4,0,Center);
			OLED_Write_Num3(0,0,Left);
			OLED_Write_Num3(9,0,Right);
			if(Key_1 == 0) //??
			{
				DelayMs(100);
				if(Key_1 == 0)
				{
					OLED_Clear();
					Flag = 2;
					SD_X = 0;
					PIT_Start(PIT1);
				}
			}
			if(Key_down == 0) //发车
			{
				DelayMs(100);
				if(Key_down == 0)
				{
					OLED_Clear();
					Flag = 0;
					PIT_Stop(PIT1);
					FTM_PWM_ChangeDuty(FTM1_CH0_PB0,0);
				}
			}
			if(Key_right == 0) //上位机
			{
				DelayMs(100);
				if(Key_right == 0)
				{
					while(1)
					{
						OLED_Clear();
						Sd_D();
						UART_Send_Con();
						FTM_PWM_ChangeDuty(FTM1_CH0_PB0,0);
					}
				}
			}
		}
		
	//发车
		while(Flag == 2)
		{
			if(TIME1flag_20ms==1)
			{
				TIME1flag_20ms=0;
				ImageCapture(Pixel);
				erzhi();
				LB();
				Sd_X();
			}
			CCD_HeiXian();
			if(leixin == 0) 
			{
				if(jiasuflag <= a4) FTM_PWM_ChangeDuty(FTM1_CH0_PB0,5000);
				if(jiasuflag >  a4) FTM_PWM_ChangeDuty(FTM1_CH0_PB0,FTMDuty_1);
			}
			if(leixin == 1) 
			{
				if(jiansuflag <= a3) FTM_PWM_ChangeDuty(FTM1_CH0_PB0,0);
				if(jiansuflag >  a3) FTM_PWM_ChangeDuty(FTM1_CH0_PB0,FTMDuty_2);
			}
			if(Key_down == 0)//菜单
			{
				DelayMs(100);
				if(Key_down == 0)
				{
					OLED_Clear();
					Flag = 0;
					PIT_Stop(PIT1);
					FTM_PWM_ChangeDuty(FTM1_CH0_PB0,0);
				}
			}
		}
	}
}
Zoltan_CrsGraph::NewTypeRef
Zoltan_CrsGraph::
operator()( OriginalTypeRef orig )
{
  origObj_ = &orig;

  int err;

  //Setup Load Balance Object
  float version;
  char * dummy = 0;
  Zoltan::LoadBalance LB( 0, &dummy, &version );
  err = LB.Create( dynamic_cast<const Epetra_MpiComm&>(orig.Comm()).Comm() );
  if( err == ZOLTAN_OK ) err = LB.Set_Param( "LB_METHOD", "GRAPH" );
#ifdef HAVE_LIBPARMETIS
  if( err == ZOLTAN_OK ) err = LB.Set_Param( "GRAPH_PACKAGE", "PARMETIS" );
  if( err == ZOLTAN_OK ) err = LB.Set_Param( "PARMETIS_METHOD", partitionMethod_ );
#endif

  //Setup Query Object
  CrsGraph_Transpose transposeTransform;
  Epetra_CrsGraph & TransGraph = transposeTransform( orig );
  ZoltanQuery Query( orig, &TransGraph );
  if( err == ZOLTAN_OK ) err = LB.Set_QueryObject( &Query );

  if( err != ZOLTAN_OK )
  { cout << "Setup of Zoltan Load Balancing Objects FAILED!\n"; exit(0); }

  //Generate Load Balance
  int changes;
  int num_gid_entries, num_lid_entries;
  int num_import;
  ZOLTAN_ID_PTR import_global_ids, import_local_ids;
  int * import_procs;
  int num_export;
  ZOLTAN_ID_PTR export_global_ids, export_local_ids;
  int * export_procs;

  orig.Comm().Barrier();
  err = LB.Balance( &changes,
                     &num_gid_entries, &num_lid_entries,
                     &num_import, &import_global_ids, &import_local_ids, &import_procs,
                     &num_export, &export_global_ids, &export_local_ids, &export_procs );
  LB.Evaluate( 1, 0, 0, 0, 0, 0, 0 );
  orig.Comm().Barrier();

  //Generate New Element List
  int numMyElements = orig.RowMap().NumMyElements();
  vector<int> elementList( numMyElements );
  orig.RowMap().MyGlobalElements( &elementList[0] );

  int newNumMyElements = numMyElements - num_export + num_import;
  vector<int> newElementList( newNumMyElements );

  set<int> gidSet;
  for( int i = 0; i < num_export; ++i )
    gidSet.insert( export_global_ids[i] );

  //Add unmoved indices to new list
  int loc = 0;
  for( int i = 0; i < numMyElements; ++i )
    if( !gidSet.count( elementList[i] ) )
      newElementList[loc++] = elementList[i];
  
  //Add imports to end of list
  for( int i = 0; i < num_import; ++i )
    newElementList[loc+i] = import_global_ids[i];

  //Free Zoltan Data
  if( err == ZOLTAN_OK )
    err = LB.Free_Data( &import_global_ids, &import_local_ids, &import_procs,
                         &export_global_ids, &export_local_ids, &export_procs );

  //Create Import Map
  NewRowMap_ = new Epetra_Map( orig.RowMap().NumGlobalElements(),
                                           newNumMyElements,
                                           &newElementList[0],
                                           orig.RowMap().IndexBase(),
                                           orig.RowMap().Comm() );

  //Create Importer
  Epetra_Import Importer( *NewRowMap_, orig.RowMap() );

  //Create New Graph
  Epetra_CrsGraph * NewGraph = new Epetra_CrsGraph( Copy, *NewRowMap_, 0 );
  NewGraph->Import( orig, Importer, Insert );
  NewGraph->FillComplete();

  Zoltan::LoadBalance LB2( 0, &dummy, &version );
  err = LB2.Create( dynamic_cast<const Epetra_MpiComm&>(orig.Comm()).Comm() );
  if( err == ZOLTAN_OK ) err = LB2.Set_Param( "LB_METHOD", "GRAPH" );
#ifdef HAVE_LIBPARMETIS
  if( err == ZOLTAN_OK ) err = LB2.Set_Param( "GRAPH_PACKAGE", "PARMETIS" );
  if( err == ZOLTAN_OK ) err = LB2.Set_Param( "PARMETIS_METHOD", partitionMethod_ );
#endif
  CrsGraph_Transpose transTrans;
  Epetra_CrsGraph & trans2 = transTrans( *NewGraph );
  ZoltanQuery query( *NewGraph, &trans2 );
  if( err == ZOLTAN_OK ) err = LB2.Set_QueryObject( &query );
  //err = LB2.Balance( &changes,
  //                   &num_gid_entries, &num_lid_entries,
  //                   &num_import, &import_global_ids, &import_local_ids, &import_procs,
  //                   &num_export, &export_global_ids, &export_local_ids, &export_procs );
  LB2.Evaluate( 1, 0, 0, 0, 0, 0, 0 );

  newObj_ = NewGraph;

  return *NewGraph;
}
Exemplo n.º 24
0
int get_sum(int w){
	int res=0;
	for(;w>0;w-=LB(w))res+=tree[w];
	return res;
	}
Exemplo n.º 25
0
int libmaus2::util::PosixExecute::execute(std::string const & command, std::string & out, std::string & err, bool const donotthrow)
{
	try
	{
		Pipe::unique_ptr_type Pstdoutpipe;
		if ( Pipe::open(Pstdoutpipe,donotthrow) < 0 )
			return EXIT_FAILURE;
		Pipe::unique_ptr_type Pstderrpipe;
		if ( Pipe::open(Pstderrpipe,donotthrow) < 0 )
			return EXIT_FAILURE;

		// fork off process
		pid_t const pid = fork();
		
		// fork failure?
		if ( pid == -1 )
		{
			int const error = errno;
		
			if ( donotthrow )
			{
				std::cerr << "Failed to fork(): " << strerror(error) << std::endl;
				return EXIT_FAILURE;
			}
			else
			{
				::libmaus2::exception::LibMausException se;
				se.getStream() << "Failed to fork(): " << strerror(error) << std::endl;
				se.finish();
				throw se;
			}
		}
		
		/* child */
		if ( pid == 0 )
		{
			try
			{
				// close read ends
				Pstdoutpipe->closeReadEnd();
				Pstderrpipe->closeReadEnd();

				// open dev null
				int nullfd = open("/dev/null",O_RDONLY);
				
				if ( nullfd < 0 )
					return EXIT_FAILURE;
				
				dup2(nullfd,STDIN_FILENO);
				dup2(Pstdoutpipe->fd[1],STDOUT_FILENO);
				dup2(Pstderrpipe->fd[1],STDERR_FILENO);
				
				Pstdoutpipe->closeWriteEnd();
				Pstderrpipe->closeWriteEnd();
				::close(nullfd);
				nullfd = -1;

				// call system
				int const ret = system ( command.c_str() );
			
				#if 0
				std::ostringstream ostr;
				ostr << "After return code " << ret << std::endl;
				std::string ostrstr = ostr.str();
				write ( STDERR_FILENO, ostrstr.c_str(), ostrstr.size() );
				#endif
				
				_exit(WEXITSTATUS(ret));
			}
			catch(std::exception const & ex)
			{
				try
				{
					std::cerr << ex.what() << std::endl;
				}
				catch(...)
				{
					
				}
				
				_exit(EXIT_FAILURE);
			}
			catch(...)
			{
				try
				{
					std::cerr << "Unknown exception in PosixExecute child process." << std::endl;
				}
				catch(...)
				{
					
				}
				
				_exit(EXIT_FAILURE);
			}
		}
		else
		{
			Pstdoutpipe->closeWriteEnd();
			Pstderrpipe->closeWriteEnd();
			
			setNonBlockFlag ( Pstdoutpipe->fd[0], true );
			setNonBlockFlag ( Pstderrpipe->fd[0], true );
			
			bool done = false;
			int status;
			
			LocalAutoArray<char> LB(8*8192);
			
			std::vector<char> outv;
			std::vector<char> errv;
			
			while ( ! done )
			{
				fd_set fileset;
				FD_ZERO(&fileset);
				FD_SET(Pstdoutpipe->fd[0],&fileset);
				FD_SET(Pstderrpipe->fd[0],&fileset);
				int nfds = std::max(Pstdoutpipe->fd[0],Pstderrpipe->fd[0])+1;
				
				struct timeval timeout = { 0,0 };
				int selret = select(nfds, &fileset, 0, 0, &timeout);

				if ( selret > 0 )
				{
					// std::cerr << "Select returned " << selret << std::endl;
					
					if ( FD_ISSET(Pstdoutpipe->fd[0],&fileset) )
					{
						ssize_t red = read ( Pstdoutpipe->fd[0], LB.begin(), LB.size() );
						// std::cerr << "Got " << red << " from stdout." << std::endl;
						if ( red > 0 )
							for ( ssize_t i = 0; i < red; ++i )
								outv.push_back(LB[i]);
					}
					if ( FD_ISSET(Pstderrpipe->fd[0],&fileset) )
					{
						ssize_t red = read ( Pstderrpipe->fd[0], LB.begin(), LB.size() );
						// std::cerr << "Got " << red << " from stderr." << std::endl;
						if ( red > 0 )
							for ( ssize_t i = 0; i < red; ++i )
								errv.push_back(LB[i]);
					}
				}
				
				status = 0;
				pid_t const wpid = waitpid(pid, &status, WNOHANG);
				
				if ( wpid == pid )
				{
					done = true;
				}
				else if ( wpid < 0 )
				{
					done = true;
				}
				else
				{
					if ( ! selret )
					{
						struct timespec waittime = { 0, 100000000 };
						nanosleep(&waittime,0);
					}
				}
			}

			setNonBlockFlag ( Pstdoutpipe->fd[0], false );
			setNonBlockFlag ( Pstderrpipe->fd[0], false );
			
			ssize_t red = -1;

			// read rest from pipes
			while ( (red = read ( Pstdoutpipe->fd[0], LB.begin(), LB.size() ) > 0 ) )
			{
				// std::cerr << "Got " << red << " from stdout in final." << std::endl;
				for ( ssize_t i = 0; i < red; ++i )
					outv.push_back(LB[i]);
			}
			while ( (red = read ( Pstderrpipe->fd[0], LB.begin(), LB.size() ) > 0 ) )
			{
				// std::cerr << "Got " << red << " from stderr in final." << std::endl;
				for ( ssize_t i = 0; i < red; ++i )
					errv.push_back(LB[i]);
			}

			// copy data
			out = std::string(outv.begin(),outv.end());
			err = std::string(errv.begin(),errv.end());
			
			if ( ! WIFEXITED(status) )
			{
				if ( donotthrow )
				{
					std::cerr << "Calling process " << command << " failed." << std::endl;
					return EXIT_FAILURE;
				}
				else
				{
					::libmaus2::exception::LibMausException se;
					se.getStream() << "Calling process " << command << " failed.";
					se.finish();
					throw se;
				}
			}
			else
			{
				return WEXITSTATUS(status);
			}
		}
	}
	catch(...)
	{
		if ( donotthrow )
			return EXIT_FAILURE;
		else
			throw;
	}
}
bool test2()
{
	int threads = 2;

	int pvpW = 1024;
	int pvpH = 1024;
	float tnear = 1.0f;
	float fov = 30;

	worker wo[threads];

	wo[0].start();
	wo[1].start();

	wo[0].init(device, "left");
	wo[1].init(device, "right");

	wo[0].setViewPort(pvpW, pvpH);
	wo[1].setViewPort(pvpW, pvpH);

	for(int f=0; f<rM.getNumOctrees(); f++)
	{
		vmml::vector<3, int> startV = rM.getStartCoord();
		vmml::vector<3, int> endV = rM.getEndCoord();
		vmml::vector<4, float> origin(startV.x() + ((endV.x()-startV.x())/3.0f), rM.getMaxHeight(), 1.1f*endV.z(), 1.0f);

		vmml::matrix<4,4,float> positionM = vmml::matrix<4,4,float>::IDENTITY;
		positionM.set_translation(vmml::vector<3,float>(origin.x(), origin.y(), origin.z()));
		vmml::matrix<4,4,float> model = vmml::matrix<4,4,float>::IDENTITY;
		model = positionM * model;

		vmml::vector<4, float> up(0.0f, 1.0f, 0.0f, 0.0f);
		vmml::vector<4, float> right(1.0f, 0.0f, 0.0f, 0.0f);
		float ft = tan(fov*M_PI/180);
		vmml::vector<4, float>LB(-ft, -ft, -tnear, 1.0f); 	
		vmml::vector<4, float>LT(-ft, ft, -tnear, 1.0f); 	
		vmml::vector<4, float>RT(0.0f, ft, -tnear, 1.0f); 	
		vmml::vector<4, float>RB(0.0f, -ft, -tnear, 1.0f); 	
		vmml::vector<4, float>LB2(0.0f, -ft, -tnear, 1.0f); 	
		vmml::vector<4, float>LT2(0.0f, ft, -tnear, 1.0f); 	
		vmml::vector<4, float>RT2(ft, ft, -tnear, 1.0f); 	
		vmml::vector<4, float>RB2(ft, -ft, -tnear, 1.0f); 	
		LB = model*LB;
		LT = model*LT;
		RB = model*RB;
		RT = model*RT;
		LB2 = model*LB2;
		LT2 = model*LT2;
		RB2 = model*RB2;
		RT2 = model*RT2;
		float w = (RB.x() - LB.x())/(float)pvpW;
		float h = (LT.y() - LB.y())/(float)pvpH;
		float w2 = (RB2.x() - LB2.x())/(float)pvpW;
		float h2 = (LT2.y() - LB2.y())/(float)pvpH;
		std::cout<<"Camera position "<<origin<<std::endl;
		std::cout<<"Frustum left"<<std::endl;
		std::cout<<LB<<std::endl;
		std::cout<<LT<<std::endl;
		std::cout<<RB<<std::endl;
		std::cout<<RT<<std::endl;
		std::cout<<"Frustum right"<<std::endl;
		std::cout<<LB2<<std::endl;
		std::cout<<LT2<<std::endl;
		std::cout<<RB2<<std::endl;
		std::cout<<RT2<<std::endl;

		up = LT-LB;
		right = RB - LB;
		right.normalize();
		up.normalize();

		
		wo[0].startFrame(up, right, origin, LB, w, h);
		wo[1].startFrame(up, right, origin, LB2, w2, h2);

		wo[0].endFrame();
		wo[1].endFrame();

		if (f < rM.getNumOctrees()-1 && !rM.loadNext())
		{
			std::cerr<<"Error loading next isosurface"<<std::endl;
			return false;
		}
	}

	wo[0].end();
	wo[1].end();

	wo[0].join();
	wo[1].join();

	return true;
}
Exemplo n.º 27
0
Arquivo: main.c Projeto: oldjohnh/car
int main(void)
{

	SystemClockSetup(ClockSource_EX50M,CoreClock_100M);
	DelayInit();
	OLED_Init();
	Sd_Init();
	chuinit_Init();
	DataInit();
	Data_Uart_Init();
	
	while(1)
	{
		Menu_Init();
		//ccd测试
		while(Flag == 1)
		{
			if(TIME1flag_20ms==1)
			{
				TIME1flag_20ms=0;
				ImageCapture(Pixel);
//				Sd_X();
//				Sd_D();
//				UART_Send_Con();
				erzhi();
				LB();
				oled_collect();
				oled_show();
			}
			CCD_HeiXian();
			OLED_ZhongXian();
			if(Key_1 == 0) //发车
			{
				DelayMs(100);
				if(Key_1 == 0)
				{
					OLED_Clear();
					Flag = 2;
					SD_X = 0;
					PIT_Start(PIT1);
				}
			}
			if(Key_down == 0) //菜单
			{
				DelayMs(100);
				if(Key_down == 0)
				{
					OLED_Clear();
					Flag = 0;
					PIT_Stop(PIT1);
					FTM_PWM_ChangeDuty(FTM1_CH0_PB0,0);
				}
			}
		}
		
	//发车
		while(Flag == 2)
		{
			if(TIME1flag_20ms==1)
			{
				TIME1flag_20ms=0;
				ImageCapture(Pixel);
				erzhi();
				LB();
//				Sd_X();
			}
			CCD_HeiXian();
			if(Center - 64 >= 7 || 63 - Center >= 7) FTM_PWM_ChangeDuty(FTM1_CH0_PB0,FTMDuty_2);
			if(Center - 64 <= 7 || 63 - Center >= 7) FTM_PWM_ChangeDuty(FTM1_CH0_PB0,FTMDuty_1);
			if(Key_down == 0)//菜单
			{
				DelayMs(100);
				if(Key_down == 0)
				{
					OLED_Clear();
					Flag = 0;
					PIT_Stop(PIT1);
					FTM_PWM_ChangeDuty(FTM1_CH0_PB0,0);
				}
			}
		}
//			while(SD_Flag)
//			{
//				Sd_D();
//				UART_Send_Con();
//			}
	}
}