示例#1
0
文件: nano.c 项目: jigsaw121/nanofic
void parse(scene** now) {
    evalparser e;
    e.nxt = malloc(sizeof(char) * (strlen((*now)->nxt)+1));
    e.nxt[0] = 0;

    choiceparser p;
    p_init(&p, *now);
    p.eval = &e;

    char* s = (*now)->nxt;
    if (eval(&s, &e)) {
        p.choose = &e_defchoose;
    }

    while(*s) {
        p.examine(s, &p);
        s++;
    }

    say(p.txt);

    p.dischoice(&p);

    while( p.choose(&p, pause(*now, &s_quit)) )
        ;

    (*now)->flag++;
    free0(e.nxt);
    free0(p.txt);
    freeall(p.choice);
}
示例#2
0
int main(void)
{
	int i;

	system_init();
	p_init();
	led_init();
	cdcacm_init();
	cdcacm_register_receive_callback(cdcacm_input_callback);
	usart_init();

	led1_on();
	led2_on();
	led3_on();
	led4_on();
	led5_on();

	for (i = 0; i < 0x800000; i++)
		__asm__("nop");

	led1_off();
	led2_off();
	led3_off();
	led4_off();
	led5_off();

	while (1) {
		cdcacm_run();
		led_process();
	}
}
示例#3
0
std::vector<std::vector<float>> solve(float x, float y, float z) {
  static bool init = false;
  static float px, py, pz;

  std::vector<std::vector<float>> ts{};
  mat lines;
  vec p_init(3);
  vec pf(3);

  if (!init) {
    init = true;
    solve_init();
    goto over_and_out;
  }

  p_init <<= px, py, pz;
  pf <<= x, y, z;

  lines = follow_line(p_init, pf, 5, R0, w, q, R0, p0);
  for (int i = 0; i < lines.size1(); i++) {
    std::vector<float> t;
    for (int j = 0; j < 5; j++)
      t.push_back(lines(i, j));
    ts.push_back(t);
  }

over_and_out:
  px = x;
  py = y;
  pz = z;
  return ts;
}
示例#4
0
int main(int argc, char *argv[])
{

    // Stack variables
    const char *file = "./hello_task.elf";
    const char *func = "main";
    int status, i, all, nargs = 1;
    const char *args[nargs];
    char argbuf[20];

    // References as opaque structures
    p_dev_t dev0;
    p_prog_t prog0;
    p_team_t team0;
    p_mem_t mem[4];

    // Execution setup
    dev0 = p_init(P_DEV_DEMO, 0);        // initialize device and team
    prog0 = p_load(dev0, file, func, 0); // load a program from file system
    all = p_query(dev0, P_PROP_NODES);   // find number of nodes in system
    team0 = p_open(dev0, 0, all);        // create a team

    // Running program
    for (i = 0; i < all; i++) {
        sprintf(argbuf, "%d", i); // string args needed to run main asis
        args[0] = argbuf;
        status = p_run(prog0, team0, i, 1, nargs, args, 0);
    }
    p_wait(team0);    // not needed
    p_close(team0);   // close team
    p_finalize(dev0); // finalize memory

    return 0;
}
示例#5
0
//jest leakage przez p_init :>
	DBDataValue::DBDataValue() // konstruktory DV robia deep-copy
	{
#ifdef DBDV_DEBUG
		cout << "Store::DBDataValue::Constructor()\n";
#endif
		p_init();
	};
示例#6
0
	DBDataValue::DBDataValue(string val)
	{
#ifdef DBDV_DEBUG
		cout << "Store::DBDataValue::Constructor(string)\n";
#endif
		p_init();
		type = Store::String;
		value.string_value = new string(val);
	};
示例#7
0
	DBDataValue::DBDataValue(double val)
	{
#ifdef DBDV_DEBUG
		cout << "Store::DBDataValue::Constructor(double)\n";
#endif
		p_init();
		type = Store::Double;
		value.double_value = new double(val);
	};
示例#8
0
	DBDataValue::DBDataValue(int val)
	{
#ifdef DBDV_DEBUG
		cout << "Store::DBDataValue::Constructor(int)\n";
#endif
		p_init();
		type = Store::Integer;
		value.int_value = new int(val);
	};
示例#9
0
	DBDataValue::DBDataValue(LogicalID* val)
	{
#ifdef DBDV_DEBUG
		cout << "Store::DBDataValue::Constructor(LogicalID*)\n";
#endif
		p_init();
		type = Store::Pointer;
		value.pointer_value = new DBLogicalID();
		*(value.pointer_value) = *val;
	};
示例#10
0
	DBDataValue::DBDataValue(vector<LogicalID*>* val)
	{
#ifdef DBDV_DEBUG
		cout << "Store::DBDataValue::Constructor(vector<LID*>*)\n";
#endif
		p_init();
		type = Store::Vector;
		value.vector_value = new vector<LogicalID*>(0);
		vector<LogicalID*>::iterator oi;
		for(oi=val->begin(); oi!=val->end(); oi++)
			value.vector_value->push_back((*oi)->clone());
	};
示例#11
0
int main(int argc, char **argv)
{
	betray_init(argc, argv, 1280, 1024, FALSE, "LayerPainter");
	sui_init();
	p_init();
	glClearColor(1, 1, 1, 0);
	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
	sui_load_settings("lp_config.cfg");
	enough_init();					/* initializing the Enough Lib, setting the max subdivision level to 3*/
//	deceive_set_intro_draw_func(NULL, NULL);
	betray_set_action_func(deceive_intro_handler, lp_input_handler);
	betray_launch_main_loop();
	return 0;
}
示例#12
0
///Main function! Kind of.
int crawl(char *start_url,
	  int download_workers,
	  int parse_workers,
	  int queue_size,
	  char * (*_fetch_fn)(char *url),
	  void (*_edge_fn)(char *from, char *to)) {

  	//start code here:
	pthread_initialize();
  	//assign queue_size to global var
  	dq_size = queue_size;
	
	_fetch_function = _fetch_fn;
	_edge_function = _edge_fn;

	p_init();
	d_init();



	dfill(start_url);
	check_visited(start_url);
	pthread_t pid[download_workers], cid[parse_workers];
	int i;
	
	for(i = 0; i < download_workers; i++){

		pthread_create(&pid[i], NULL, download_thread, NULL);
	}
	for(i = 0; i < parse_workers; i++){

		pthread_create(&cid[i], NULL, parse_thread, NULL);
	}
	


	pthread_mutex_lock(&w_lock);
	while(work > 0){
		pthread_cond_wait(&done, &w_lock);
	}

	pthread_mutex_unlock(&w_lock);
	
  	return 0;
}
示例#13
0
	DBDataValue::DBDataValue(const DataValue& dv)
	{
#ifdef DBDV_DEBUG
		cout << "Store::DBDataValue::Constructor(DataValue&)\n";
#endif
		p_init();
		setSubtype(dv.getSubtype());
		cloneSetOfLid(dv.getSubclasses(), this->subclasses);
		cloneSetOfLid(dv.getClassMarks(), this->classMarks);
		switch(dv.getType()) {
			case Store::Integer:	setInt(dv.getInt()); break;
			case Store::Double:  setDouble(dv.getDouble()); break;
			case Store::String:  setString(dv.getString()); break;
			case Store::Pointer:	setPointer(dv.getPointer()); break;
			case Store::Vector:  setVector(dv.getVector()); break;
			default:
				cout << "DV ERROR\n"; break;
		}
	};
示例#14
0
文件: main.c 项目: sirianray/lblc
int main(int argc, char *argv[]){
	MPI_Init(&argc, &argv);
        MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, 0, MPI_INFO_NULL, &shmcomm);
        MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
        MPI_Comm_rank(MPI_COMM_WORLD, &myid);

	double t_begin;
	int i, j, k, ii, id, id1;

	t_begin = MPI_Wtime();		// record the begining CPU time
	
	read_param();
	lattice_vec();
	allocate();
	p_allocate();

	if (flow_on!=0) {
		build_stream();
	}

	if (Q_on!=0) {
		build_neighbor();		
	}

	init_surf();
	add_patch();
	p_init();
	p_iden();
	init();

	if (flow_on!=0) cal_fequ(f);	
	if (Q_on!=0) cal_dQ();

	if (Q_on!=0 && flow_on!=0 && newrun_on!=0) {
		while(qconverge==0) {
			t_current++;
			for (ii=0; ii<n_evol_Q; ii++) {
                                cal_dQ();
                                evol_Q();
                        }
			if (t_current%t_print==0) monitor();
		}
		e_tot     =-1;
		k_eng     =-1;
		qconverge = 0;	
		uconverge = 0;
		t_current =-1;
	}

	if (Q_on!=0 && flow_on!=0) {
		cal_W();
		cal_stress();
		cal_sigma_p();
	}
        MPI_Barrier(MPI_COMM_WORLD);

	output1(1,'z',Nx/2,Ny/2);
	output3(1);
	if(myid==0) printf("Q initialized\n");
	MPI_Barrier(MPI_COMM_WORLD);

	while (t_current<t_max && uconverge*qconverge==0) {
		e_toto=e_tot;
		if (Q_on!=0 && qconverge==0) {
			if (flow_on!=0 && uconverge==0) cal_W();
			for (ii=0; ii<n_evol_Q; ii++) {
				cal_dQ();
				evol_Q();
			}			
		}

		if (flow_on!=0 && uconverge==0) {
			if (Q_on!=0 && qconverge==0) {
				cal_stress();
				cal_sigma_p();
			}
			evol_f(f,f2);
		}

		if (Q_on!=0 && qconverge==0) {
			if (flow_on!=0 && uconverge==0) cal_W();
			for (ii=0; ii<n_evol_Q; ii++) {
				cal_dQ();
				evol_Q();
			}			
		}

		if (flow_on!=0 && uconverge==0) {
			if (Q_on!=0 && qconverge==0) {
				cal_stress();
				cal_sigma_p();
			}
			evol_f(f2,f);
		}
		
		if (t_current%t_print==0) monitor();
		if (t_current%t_write==0) {
			output1(0,'z',Nx/2,Ny/2);
			output3(0);
			fflush(stdout);
		}
		t_current++;
	}
	
	
	output_time(t_begin);
	output1(0,'z',Nx/2,Ny/2);
	output3(0);
	
	write_restart();

	p_deallocate();
	deallocate();

	return 0;
}
示例#15
0
/***********************************************************************
 **  POST_PRINT.C mainline.	**
 ***********************************************************************/
void main(int argc, char *argv[])
{
    int num_read, i;
    int one_shot;
    int pipe_in, pipe_out;
    int result;
	char tp_extend[18];
	char *new_Psf_path_ptr;
    char *parse_buff_ptr;

	umask(0);
    set_sigs();					/* get all traces out at end */
    p_init(0);
	lc_init(1);
	memset ( (char *)&ObjPageWn.page_number[0], 0,
			 sizeof (struct obj_pg_wn) );
	obj_wn_count = 0;
    one_shot = 0;

	Current_FgColor = 1;			/*  BUG 594q Initialize current color to black     */
	Current_FgShade = 100;			/*  BUG 594q Initialize current shade to 100%   */
    msg_parse_args(argc, argv, KEYWORD_COUNT, msg);
    pipe_in = atoi(msg[0].answer);
    pipe_out = atoi(msg[1].answer);
    if((pipe_in == 0) && (pipe_out ==0))
		one_shot = 1;			/* don't read from pipe */
    p_info(PI_INFO, "Postprint Startup.\n"); /* log in first message. */
    strcpy (overflow_path,"overflow.pos1"); /* Build name of overflow-text
											   temp file, using ipc suffix.*/
	bmtop = 0;					/* Init dynamic PDF bookmark mem array.  */
	uidtop = 0;					/* Init dynamic PDF bookmark-idrid mem array.  */

/***************************** start of big loop ***************************/
    for(;;)
    {
		if (p_LogFd)
		{
			fclose (p_LogFd);
			p_LogFd = NULL;
		}
		if (TrailerName)
		{
		        fclose(TrailerName);
			TrailerName = NULL;
		}
		if (PrologName)
		{
		        fclose(PrologName);
			PrologName = NULL;
		}

		p_LogCnt = 0;
		if (Fofd)
			p_close(Fofd);
		FoName[0] = 0;
		parse_buff = p_alloc(2048);
		if ( !m_fprintf_size)
		{
			m_fprintf_size = 4096;
			m_fprintf_buff = p_alloc(m_fprintf_size);
		}
		if( !one_shot)
		{						/* read from the pipe */
			num_read = read(pipe_in, parse_buff, 2048);
			switch (num_read)
			{
			  case -1:
				p_info(PI_ELOG, "pipe read failed\n");
				exit(1);
			  case 0:
				p_info(PI_ELOG, "pipe_in EOF\n");
				exit(1);
			  default:
				break;
			}					/* end switch(num_read) */
#ifdef TRACE
			if(debugger_trace)
				p_info(PI_TRACE, "pipe num_read= %d, '%s' \n",num_read,parse_buff);
#endif
			msg_parse(parse_buff, num_read, KEYWORD_COUNT, msg);
        }						/* end of pipe read */
		else
		{						/* read from arg & argv or from file */
			if ((one_shot == 1) && !source_pfd)
			{
			    if ( msg[44].answer[0])
				{				/* KEYWORD 'source', read from file */
					one_shot = 2;
					if((source_pfd = p_open(NO_STRING, OTHER_FILE, NO_STRING,
											msg[44].answer, "r")) == 0)
					{			
						p_info(PI_ELOG, "Failed to open source '%s'\n",msg[44].answer);
						exit(2);
					}
				}
			}
			if ( source_pfd)
			{					/* get next job from source file */
				if (p_fgets(parse_buff, 2048, source_pfd) == 0)
				{
					p_info(PI_ELOG, "source file empty\n");
					exit(3);
				}
				parse_buff_ptr = parse_buff;
				while ( *parse_buff_ptr)
				{
					if ( *parse_buff_ptr == '\012')
					{
						*parse_buff_ptr = 0;
						break;
					}
					parse_buff_ptr++;
				}
				msg_parse (parse_buff, (int)(parse_buff_ptr - parse_buff + 1),
						   KEYWORD_COUNT, msg);
			}
		}
#if LPMfloat
		for (i = 0; i < LPM_MaxOption; i++)
			LPMK[i] = lpm_option(i);
#else
		LPMK = lpm_query(LPM_Options,LPM_CurrRev);
#endif
        result = job_setup();
        p_free(parse_buff);
        if(result)
        {						/* only if setting traces */
			if(!one_shot)
			{
				if((num_read = write(pipe_out, "0", 2))== -1)
				{
					p_info(PI_ELOG, "write to pipe failed\n");
					exit(1);
				}
				else
					continue;	/* traces only, get next pipe message */
			}
			exit(1);
        }
        strcpy(tpname, JobName); /* TP filename. */
		if ( FileType)
		{						/* layout */
			tp_extend[0] = 0;
			if (MasterNameFlag)
				sprintf (tp_extend, ".%s", PageName);
			if ( LYPrintFlag)
				strcat (tp_extend, ".lyp");
			strcat (tpname, tp_extend);
			if ( (FirstPage >= 0) && ( !MasterNameFlag) )
			{
				if (LastPage != FirstPage)
					sprintf(tp_extend, ".%d_%d",FirstPage,LastPage);
				else			/* if equal only use one page number */
					sprintf(tp_extend, ".%d",FirstPage);
				strcat(tpname,tp_extend);
			}
			else if (BookPrint)
			{
				if (LastParentIndex > ParentIndex)
					sprintf(tp_extend, ".u%d_u%d",ParentIndex,LastParentIndex);
				else
					sprintf(tp_extend, ".u%d",ParentIndex);
				strcat(tpname,tp_extend);
			}
		}
		if (EpsFlag)
		   strcpy (logname, p_path(TreeName, EPS_FILE, SubDirName, tpname));
		else if (BookPrint)
		   strcpy (logname, p_path(TreeName, OUTPUT_FILE, ParentDirName, tpname));
		else
		   strcpy (logname, p_path(TreeName, OUTPUT_FILE, SubDirName, tpname));
		strcpy (prologname, logname);
		strcpy (trailername, logname);

		strcat (logname, ".log");
		p_LogFd = fopen (logname, "w+");

		strcat (prologname, ".plog");
		PrologName = fopen(prologname, "w+");

		strcat (trailername,".ptrl");
		TrailerName = fopen(trailername, "w+");

		new_Psf_path_ptr = p_path(TreeName, USERDATA, UserdataPath,
								  PsfTableName);
		if ( strcmp( Psf_path_name, new_Psf_path_ptr) )
		{						/* no match, need a new name and Psftable */
			strcpy(Psf_path_name, new_Psf_path_ptr);
			if ( !Psftable_load_with_name(TreeName, SubDirName,
										  PsfTableName) )
			{					/* bad psftable load, abort */
				p_info(PI_ELOG, "Unable to open file '%s'",Psf_path_name);
				exit(101);
			}
			PsfNameIndex = 0;
			PsfCodeIndex = 0;
			HelveticaFontNumber = 0;
			for (i=0; i<MaxPentaFont; i++)
			{					/* find Helvetica */
				if ( PentaToPsf[i].name)
				{
					if ( !strcmp(PentaToPsf[i].name, "Helvetica") )
						HelveticaFontNumber  = i;
				}
			}
		}						/* psftable loaded */

		if (HdrPNamPrt)
			get_prt_name();  /*  Bug 367p get actual printer name from .psh file */
		else
			PrtNam[0] = 0;
	
		getpgsize();			/* Parse header lines */

		if(lnumbers & 1) {		/* Print line numbers?  */
			if (!FileType) {	/* In galley mode:  */
				OffL += 40;		/* =15pts space at left + 25 for big line number  */
				if (LineStats)
					OffL += 30;	/* =5pts at left + 25 line# + 40 for band & ls  */
			}
			else				/* In page mode:  */
				OffL += 10;		/* just 10 pts of room.  */
		}
/***********************************************************************
 **  Call the PostScript mainline processor.			      **
 ***********************************************************************/
		
		psmain();
		
/***********************************************************************
 **  Wrap it all up.						      **
 ***********************************************************************/
		if (EpsFlag)
		   strcpy (logname, p_path(TreeName, EPS_FILE, SubDirName, tpname));
		else if (BookPrint)
		   strcpy (logname, p_path(TreeName, OUTPUT_FILE, ParentDirName, tpname));
		else
		   strcpy (logname, p_path(TreeName, OUTPUT_FILE, SubDirName, tpname));
		if (PrinterName[0])
		{						/* output to the printer queue */
			fflush (p_LogFd);
			if( !GraphicsPresentFlag)
				result = 0;
			else
				result = 1;

			sprintf(shell_msg,"/usr/local/bin/%s.psh %s %d %d %s %s %d %d %d %d",
                PrinterName, logname, result, FileType, TreeName,
				SubDirName, FirstPage, LastPage, HNJ_LockFailureFlag,
				DistillFlag);
			system(shell_msg);
		}

		/* If user asked for "Distill to PDF" (and there's no H&J lock), then
			test to find the newest .tp, .eps or .ps in the .drawer, and see
			if it's newer than any .pdf file there.
			If so, this means the printer script did NOT create a .pdf, so
			distill the .tp to .pdf using ghostscript's ps2pdf script here.
		*/
		if (DistillFlag && !HNJ_LockFailureFlag)
		{
			struct stat tpstat, psstat, pdfstat;
			int tpind, psind, pdfind, buildpdf;
			char *dotptr;

			strcpy (prologname, logname);
			strcat (prologname, ".pdf");	/* Get stat of *.tp.pdf file:  */
			pdfind = stat(prologname, &pdfstat);
			if (pdfind)						/* If that doesn't exit, alt try:  */
			{
				strcpy (prologname, logname);
				dotptr = strrchr (prologname, '.');
				*dotptr = 0;				/* Strip whatever suffix we have,  */
				strcat (prologname, ".pdf");/*  replace with .pdf.  */
											/* Get stat of that pdf file:  */
				pdfind = stat(prologname, &pdfstat);
			}

			tpind = stat(logname, &tpstat);	/* Get stat of .tp (or .eps) file  */
			psind = 1;						/* (assume unused)  */
			if (!EpsFlag)					/* If we started with .tp file,  */
			{								/*  also get stat of .ps file:  */
				strcpy (prologname, logname);
				strcpy (&prologname[strlen(logname)-3], ".ps");
				psind = stat(prologname, &psstat);
			}

			buildpdf = 0;				/* Assume no need to build a .pdf  */
			if (!tpind &&				/* If .tp (or .eps) exists, and  */
				(psind ||				/*  .ps does not, or .tp is newer, then:  */
				 tpstat.st_mtime > psstat.st_mtime))
			{
				strcpy (prologname, logname);	/* (use .tp name)  */
										/*  if there's no .pdf or it's older,  */
				if (pdfind || tpstat.st_mtime > pdfstat.st_mtime)
					buildpdf = 1;		/*  set flag to distill the .tp file.  */
			}
			else 
			if (!psind &&				/* If .ps exists, and  */
				(tpind ||				/*  .tp does not, or .ps is newer, then:  */
				 tpstat.st_mtime <= psstat.st_mtime))
			{
				strcpy (logname, prologname);	/* (use .ps name)  */
										/*  if there's no .pdf or it's older,  */
				if (pdfind || psstat.st_mtime > pdfstat.st_mtime)
					buildpdf = 1;		/*  set flag to distill the .ps file.  */
			}
			else						/* Neither exist, forget it.   */
				;

			if (buildpdf)				/* If we decided to distill a .pdf, then  */
			{							/* build basename by stripping suffix,  */
				*(dotptr = strrchr (prologname, '.')) = 0;
										/* build little script calling ps2pdf,  */
			  	sprintf (shell_msg,
				"PATH=/usr/local/bin/ghostscript:$PATH; export PATH; ps2pdf  %s %s.pdf",
				logname, prologname);

				p_info(PI_INFO, "Executing distillation to PDF from Postprint\n");
				system(shell_msg);		/* and send it off, wait for done.  */
			}
		}					/* end if (DistillFlag && !HNJ_LockFailureFlag)  */

		p_free(m_fprintf_buff);
		m_fprintf_size = 0;
		if(!one_shot)
		{
			if((num_read =write(pipe_out, "0", 2))== -1)
			{
				p_info(PI_ERROR, "write to pipe failed\n");
				exit(1);
			}
			else
				p_info(PI_INFO, "Post completed for %s \n",tpname);
		}
		else
		{
			if (!source_pfd)
			{
				p_info(PI_INFO, "Post completed for %s, program exit. \n",JobName);
				break;
			}
			else
				p_info(PI_INFO, "Post completed for %s \n",JobName);
		}
    }							/* end of for(;;) */
    exit(ExitError);
}								/* end of PSMAIN */
示例#16
0
KVisualItem::KVisualItem(QGraphicsItem *parent, Qt::WindowFlags wFlags) :
    QGraphicsWidget(parent, wFlags)
{
    p_init();
}
示例#17
0
bool AbstractExecutor::init(VoltDBEngine* engine,
                            const ExecutorVector& executorVector)
{
    assert (m_abstractNode);

    //
    // Grab the input tables directly from this node's children
    //
    vector<Table*> input_tables;
    for (int ctr = 0,
             cnt = static_cast<int>(m_abstractNode->getChildren().size());
         ctr < cnt;
         ctr++)
    {
        Table* table = m_abstractNode->getChildren()[ctr]->getOutputTable();
        if (table == NULL) {
            VOLT_ERROR("Output table from PlanNode '%s' is NULL",
                       m_abstractNode->getChildren()[ctr]->debug().c_str());
            return false;
        }
        input_tables.push_back(table);
    }
    m_abstractNode->setInputTables(input_tables);

    // Some tables have target tables (scans + operations) that are
    // based on tables under the control of the local storage manager
    // (as opposed to an intermediate result table). We'll grab them
    // from the VoltDBEngine. This is kind of a hack job here... is
    // there a better way?

    AbstractScanPlanNode* scan_node =
        dynamic_cast<AbstractScanPlanNode*>(m_abstractNode);
    AbstractOperationPlanNode* oper_node =
        dynamic_cast<AbstractOperationPlanNode*>(m_abstractNode);
    if (scan_node || oper_node)
    {
        Table* target_table = NULL;

        string targetTableName;
        if (scan_node) {
            targetTableName = scan_node->getTargetTableName();
            target_table = scan_node->getTargetTable();
        } else if (oper_node) {
            targetTableName = oper_node->getTargetTableName();
            target_table = oper_node->getTargetTable();
        }

        // If the target_table is NULL, then we need to ask the engine
        // for a reference to what we need
        // Really, we can't enforce this when we load the plan? --izzy 7/3/2010
        bool isPersistentTableScan = (scan_node != NULL && scan_node->isPersistentTableScan());
        if (target_table == NULL && isPersistentTableScan) {
            target_table = engine->getTableByName(targetTableName);
            if (target_table == NULL) {
                VOLT_ERROR("Failed to retrieve target table '%s' "
                           "from execution engine for PlanNode '%s'",
                           targetTableName.c_str(),
                           m_abstractNode->debug().c_str());
                return false;
            }
            TableCatalogDelegate * tcd = engine->getTableDelegate(targetTableName);
            assert(tcd != NULL);
            if (scan_node) {
                scan_node->setTargetTableDelegate(tcd);
            } else if (oper_node) {
                oper_node->setTargetTableDelegate(tcd);
            }
        }
    }

    // Call the p_init() method on our derived class
    if (!p_init(m_abstractNode, executorVector)) {
        return false;
    }

    if (m_tmpOutputTable == NULL) {
        m_tmpOutputTable = dynamic_cast<AbstractTempTable*>(m_abstractNode->getOutputTable());
    }

    return true;
}
示例#18
0
文件: matmul-host.c 项目: peteasa/pal
int main(int argc, char *argv[])
{
	p_mem_t shared_mem, results_mem;
	uint32_t eram_base;
	char results[1024] = { '\0' };
	int device_cols, device_rows, nside;
	p_dev_t dev;
	p_prog_t prog;
	p_team_t team;
	p_coords_t size;
	p_coords_t start = { .row = 0, .col = 0 };

	unsigned int msize;
	float        seed;
	unsigned int addr; //, clocks;
	size_t       sz;
	int          verbose=0;
	double       tdiff[3];
	int          result, retval = 0;

	msize     = 0x00400000;

	get_args(argc, argv);

	fo = stderr;
	fi = stdin;
	printf( "------------------------------------------------------------\n");
	printf( "Calculating:   C[%d][%d] = A[%d][%d] * B[%d][%d]\n", _Smtx, _Smtx, _Smtx, _Smtx, _Smtx, _Smtx);
	seed = 0.0;
	if(verbose){
	  printf( "Seed = %f\n", seed);
	}

	dev = p_init(P_DEV_EPIPHANY, 0);
	if (p_error(dev)) {
		fprintf(stderr, "Error initializing PAL\n");
		return p_error(dev);
	}

	device_cols = p_query(dev, P_PROP_COLS);
	device_rows = p_query(dev, P_PROP_ROWS);

	// Use min size
	nside = device_cols > device_rows ? device_cols : device_rows;

	if (nside < 4) {
		fprintf(stderr, "Error: Too small device, need at least 4x4\n");
		return 1;
	}

	// Either 1024, 256, 64, or 16 cores (side must be power of two),
	nside = nside >= 32 ? 32 : nside >= 16 ? 16 : nside >= 8 ? 8 : 4;

	size.row = nside;
	size.col = nside;
	team = p_open4(dev, P_TOPOLOGY_2D, &start, &size);
	printf("Using team of size %d\n", p_team_size(team));
	if (p_error(team)) {
		fprintf(stderr, "Error opening team\n");
		return p_error(team);
	}

	prog = p_load(dev, ar.elfFile, 0);

	eram_base = (unsigned) p_query(dev, P_PROP_MEMBASE);
	shared_mem = p_map(dev, eram_base, msize);

	// Clear mailbox contents
	memset(&Mailbox, 0, sizeof(Mailbox));
	p_write(&shared_mem, &Mailbox, 0, sizeof(Mailbox), 0);

	// Generate operand matrices based on a provided seed
	matrix_init((int)seed);

#ifdef __WIPE_OUT_RESULT_MATRIX__
	// Wipe-out any previous remains in result matrix (for verification)
	addr = offsetof(shared_buf_t, C[0]);
	sz = sizeof(Mailbox.C);
	if(verbose){
	  printf( "Writing C[%uB] to address %08x...\n", (unsigned) sz, addr);
	}
	p_write(&shared_mem, (void *) Mailbox.C, addr, sz, 0);
#endif

	/* Wallclock time */
	clock_gettime(CLOCK_MONOTONIC, &timer[0]);
	/* Clock CPUTIME too. We don't want to indicate failure just
	 * because the system was under high load. */
	clock_gettime(CLOCK_THREAD_CPUTIME_ID, &timer[4]);

	// Copy operand matrices to Epiphany system
	addr = offsetof(shared_buf_t, A[0]);
	sz = sizeof(Mailbox.A);
	if(verbose){
	  printf( "Writing A[%uB] to address %08x...\n", (unsigned) sz, addr);
	}
	p_write(&shared_mem, (void *) Mailbox.A, addr, sz, 0);

	addr = offsetof(shared_buf_t, B[0]);
	sz = sizeof(Mailbox.B);
	if(verbose){
	  printf( "Writing B[%uB] to address %08x...\n", (unsigned) sz, addr);
	}
	p_write(&shared_mem, (void *) Mailbox.B, addr, sz, 0);
	// Call the Epiphany matmul() function

	if(verbose){
	  printf( "GO Epiphany! ...   ");
	}
	if(verbose){
	  printf("Loading program on Epiphany chip...\n");
	}

	p_arg_t args[] = { &nside, sizeof(nside), true };
	if (p_run(prog, "matmul", team, 0, p_team_size(team), 1, args, 0)) {
		fprintf(stderr, "Error loading Epiphany program.\n");
		exit(1);
	}

	// Read result matrix and timing
	addr = offsetof(shared_buf_t, C[0]);
	sz = sizeof(Mailbox.C);
	if(verbose){
	  printf( "Reading result from address %08x...\n", addr);
	}
	p_read(&shared_mem, (void *) Mailbox.C, addr, sz, 0);

	clock_gettime(CLOCK_MONOTONIC, &timer[1]);
	clock_gettime(CLOCK_THREAD_CPUTIME_ID, &timer[5]);


	// Calculate a reference result
	clock_gettime(CLOCK_THREAD_CPUTIME_ID, &timer[2]);
#ifndef __DO_STRASSEN__
	matmul(Mailbox.A, Mailbox.B, Cref, _Smtx);
#else
	matmul_strassen(Mailbox.A, Mailbox.B, Cref, _Smtx);
#endif
	clock_gettime(CLOCK_THREAD_CPUTIME_ID, &timer[3]);
	addr = offsetof(shared_buf_t, core.clocks);
	sz = sizeof(Mailbox.core.clocks);
	if(verbose){
	  printf( "Reading time from address %08x...\n", addr);
	}
	p_read(&shared_mem, &Mailbox.core.clocks, addr, sizeof(Mailbox.core.clocks), 0);
//	clocks = Mailbox.core.clocks;





	// Calculate the difference between the Epiphany result and the reference result
	matsub(Mailbox.C, Cref, Cdiff, _Smtx);

	tdiff[0] = (timer[1].tv_sec - timer[0].tv_sec) * 1000 + ((double) (timer[1].tv_nsec - timer[0].tv_nsec) / 1000000.0);
//	tdiff[0] = ((double) clocks) / eMHz * 1000;
	tdiff[1] = (timer[3].tv_sec - timer[2].tv_sec) * 1000 + ((double) (timer[3].tv_nsec - timer[2].tv_nsec) / 1000000.0);
	tdiff[2] = (timer[5].tv_sec - timer[4].tv_sec) * 1000 + ((double) (timer[5].tv_nsec - timer[4].tv_nsec) / 1000000.0);


	// If the difference is 0, then the matrices are identical and the
	// calculation was correct
	if (iszero(Cdiff, _Smtx))
	  {

	    printf( "Epiphany(time) %9.1f msec  (@ %03d MHz)\n", tdiff[0], eMHz);
	    printf( "Host(time)     %9.1f msec  (@ %03d MHz)\n", tdiff[1], aMHz);
	    printf( "------------------------------------------------------------\n");
	    printf( "TEST \"matmul-16\" PASSED\n");
	    retval = 0;
	} else {
	  printf( "\n\nERROR: C_epiphany is different from C_host !!!\n");
	  printf( "TEST \"matmul-16\" FAILED\n");
	  retval = 1;
	}

#if 0
#ifdef __DUMP_MATRICES__
	printf( "\n\n\n");
	printf( "A[][] = \n");
	matprt(Mailbox.A, _Smtx);
	printf( "B[][] = \n");
	matprt(Mailbox.B, _Smtx);
	printf( "C[][] = \n");
	matprt(Mailbox.C, _Smtx);
	printf( "Cref[][] = \n");
	matprt(Cref, _Smtx);

	int i, j;
	for (i=0; i<_Nside; i++)
		for (j=0; j<_Nside; j++)
		{
			e_read(pEpiphany, i, j, 0x2000+0*sizeof(float), &Aepi[(i*_Score+0)*_Smtx + j*_Score], 2*sizeof(float));
			e_read(pEpiphany, i, j, 0x2000+2*sizeof(float), &Aepi[(i*_Score+1)*_Smtx + j*_Score], 2*sizeof(float));
			e_read(pEpiphany, i, j, 0x4000+0*sizeof(float), &Bepi[(i*_Score+0)*_Smtx + j*_Score], 2*sizeof(float));
			e_read(pEpiphany, i, j, 0x4000+2*sizeof(float), &Bepi[(i*_Score+1)*_Smtx + j*_Score], 2*sizeof(float));
		}
	printf( "Aepi[][] = \n");
	matprt(Aepi, _Smtx);
	printf( "Bepi[][] = \n");
	matprt(Bepi, _Smtx);
#endif
#endif



	// p_unmap ...
	p_close(team);
	p_finalize(dev);

	return retval;
}


// Initialize operand matrices
void matrix_init(int seed)
{
	int i, j, p;

	p = 0;
	for (i=0; i<_Smtx; i++)
		for (j=0; j<_Smtx; j++)
			Mailbox.A[p++] = (i + j + seed) % _MAX_MEMBER_;

	p = 0;
	for (i=0; i<_Smtx; i++)
		for (j=0; j<_Smtx; j++)
			Mailbox.B[p++] = ((i + j) * 2 + seed) % _MAX_MEMBER_;

	p = 0;
	for (i=0; i<_Smtx; i++)
		for (j=0; j<_Smtx; j++)
			Mailbox.C[p++] = 0x8dead;

	return;
}