Esempio n. 1
0
void imprimir_recorridos(int n)
{	char c[5];
	sprintf(c,"%d",n);
	print_on_screen(&c[0],distancia,630,fcolor,recorrido_ttf);
	distancia+=30;
	SDL_Flip(screen);
}
Esempio n. 2
0
void ventana_alerta(char *ptr)
{	SDL_Rect pos;
	pos.x=200;pos.y=230;
	SDL_BlitSurface(window_alerta,NULL,screen,&pos);
	print_on_screen(ptr,280,260,fcolor,font);
	pos.x=440;pos.y=340;
	SDL_BlitSurface(boton_ok[0],NULL,screen,&pos);
	SDL_Flip(screen);
	SDL_Event evento;
	while(1)
	{	SDL_WaitEvent(&evento);
                if(evento.type==SDL_MOUSEMOTION)
                {	if(posicion_cursor(440,505,340,363,evento.motion.x,evento.motion.y))
				SDL_BlitSurface(boton_ok[1],NULL,screen,&pos);
			else
			        SDL_BlitSurface(boton_ok[0],NULL,screen,&pos);
			SDL_Flip(screen);
		}
		else if(evento.type==SDL_MOUSEBUTTONDOWN)
		{	if(posicion_cursor(440,505,340,363,evento.button.x,evento.button.y))
			{	draw_interface_principal();
                                print_arbol(A,0);
                                SDL_Flip(screen);
				return;
			}
		}
		if(evento.type==SDL_KEYDOWN && evento.key.keysym.sym==27)
                {       draw_interface_principal();
                        draw_menu_botones();
			SDL_Flip(screen);
                        return;
                }
	} 
	
}
Esempio n. 3
0
void postorden(ARBOL A)
{       if(A==NULL)
                return;
        postorden(A->izq);
        postorden(A->der);
	char c[5];
	SDL_BlitSurface(nodo_visitado,NULL,screen,&(A->pos));
        sprintf(c,"%d ",A->dato);
        print_on_screen(&c[0],A->pos.x+6,A->pos.y+6,fcolor,arbol_ttf);
        SDL_Flip(screen);
        SDL_Delay(1500);
        SDL_BlitSurface(nodo_img,NULL,screen,&(A->pos));
        sprintf(c,"%d ",A->dato);
        print_on_screen(&c[0],A->pos.x+6,A->pos.y+6,fcolor,arbol_ttf);
        imprimir_recorridos(A->dato);
        SDL_Flip(screen);       
}
Esempio n. 4
0
void print_on_screen3(char *fmt, ...)
{
	int i;
	char buf[512];
	va_list arg = (va_list)((char *)(&fmt) + 4);
	i = vsprintf(buf,fmt,arg);
	
	print_on_screen(buf);
}
Esempio n. 5
0
File: fs.c Progetto: jjhlzn/haribote
/**
 * <Ring 1> Get the super block from super_block[].
 * 
 * @param dev Device nr.
 * 
 * @return Super block ptr.
 *****************************************************************************/
PUBLIC struct super_block * get_super_block(int dev)
{
	struct super_block * sb = super_block;
	for (; sb < &super_block[NR_SUPER_BLOCK]; sb++)
		if (sb->sb_dev == dev)
			return sb;

	print_on_screen("super block of devie not found.");

	return 0;
}
Esempio n. 6
0
void draw_menu_botones()
{	SDL_Rect pos,posi;
	char c[4];
	pos.x=20; pos.y=12;SDL_BlitSurface(boton_insertar[0],NULL,screen,&pos);
	posi.x=pos.x+boton_insertar[0]->w+2;sprintf(c,"[1]");
	posi.y=2;
	print_on_screen(&c[0],posi.x,posi.y+10,fcolor,font_op);

        pos.x+=125;SDL_BlitSurface(boton_eliminar[0],NULL,screen,&pos);
        posi.x=pos.x+boton_insertar[0]->w+2;sprintf(c,"[2]");
        print_on_screen(&c[0],posi.x,posi.y+10,fcolor,font_op);

	pos.x+=125; SDL_BlitSurface(boton_recorridos[0],NULL,screen,&pos);
	posi.x=pos.x+boton_insertar[0]->w+2;sprintf(c,"[3]");
        print_on_screen(&c[0],posi.x,posi.y+10,fcolor,font_op);

	pos.x+=550; SDL_BlitSurface(boton_salir[0],NULL,screen,&pos);
	posi.x=pos.x+boton_insertar[0]->w+2;sprintf(c,"[4]");
        print_on_screen(&c[0],posi.x,posi.y+10,fcolor,font_op);

}
Esempio n. 7
0
PUBLIC void panic(const char *fmt, ...)
{
	int i;
	char buf[256], buf2[256];

	/* 4 is the size of fmt in the stack */
	va_list arg = (va_list)((char*)&fmt + 4);

	i = vsprintf(buf, fmt, arg);

	sprintf(buf2,"%c !!panic!! %s", MAG_CH_PANIC, buf);
	print_on_screen(buf2);

	/* should never arrive here */
	//ud2();
	for(;;);
}
Esempio n. 8
0
void print_arbol(ARBOL A,int n)
{	if(A==NULL)
		return;	
	if(A->der!=NULL)
	{	SDL_Rect posi;
		posi.y=(A->pos).y+10;
        	posi.x=(A->pos).x+20;
                SDL_BlitSurface(flechader[n],NULL,screen,&posi);
	}
	if(A->izq!=NULL)
	{	SDL_Rect posi;
		posi.y=(A->pos).y+10;
        	posi.x=(A->pos).x-((flechaizq[n]->w-20));
                SDL_BlitSurface(flechaizq[n],NULL,screen,&posi);
	}
	SDL_BlitSurface(nodo_img,NULL,screen,&(A->pos));
	char c[5];
	sprintf(c,"%d",A->dato);
	print_on_screen(&c[0],A->pos.x+6,A->pos.y+6,fcolor,arbol_ttf);
	//SDL_Flip(screen);
	print_arbol(A->izq,n+1);
	print_arbol(A->der,n+1);
}
Esempio n. 9
0
/**
 * Allocate a bit in inode-map.
 * 
 * @param dev  In which device the inode-map is located.
 * 
 * @return  I-node nr.
 *****************************************************************************/
PRIVATE int alloc_imap_bit(int dev)
{
	int inode_nr = 0;
	int i, j, k;

	int imap_blk0_nr = 1 + 1; /* 1 boot sector & 1 super block */
	struct super_block * sb = get_super_block(dev);

	for (i = 0; i < sb->nr_imap_sects; i++) {
		RD_SECT(dev, imap_blk0_nr + i);

		for (j = 0; j < SECTOR_SIZE; j++) {
			/* skip `11111111' bytes */
			if (fsbuf[j] == 0xFF)
				continue;

			/* skip `1' bits */
			for (k = 0; ((fsbuf[j] >> k) & 1) != 0; k++) {}

			/* i: sector index; j: byte index; k: bit index */
			inode_nr = (i * SECTOR_SIZE + j) * 8 + k;
			fsbuf[j] |= (1 << k);

			/* write the bit to imap */
			WR_SECT(dev, imap_blk0_nr + i);
			break;
		}

		return inode_nr;
	}

	/* no free bit in imap */
	//panic("inode-map is probably full.\n");
	print_on_screen("inode-map is probably full.\n");

	return 0;
}
void    pieCalculationGMSP (cl_uint numDevices,float *finalPieValue,cl_device_id *devices, cl_program program,cl_context context,int numOfIntervals)
{
	cl_event                gpuExec[1];
        cl_int err;	
	cl_command_queue cmdQueue;   //holds command queue object
	cl_kernel kernel;		//holds kernel object
	cl_mem d_area,d_numOfIntervals;		//holds device input output buffer
	cl_event                events;        // events
	size_t globalWorkSize[1]={numOfIntervals}; //holds global group size
	double                  gflops=0.0;             //holds total achieved gflops
        cl_ulong startTime, endTime,elapsedTime;        //holds time
        float executionTimeInSeconds;                    //holds total execution time
	  
    	/*create command queue*/
        cmdQueue = clCreateCommandQueue(context, devices[0],  CL_QUEUE_PROFILING_ENABLE, &err);
        if( err != CL_SUCCESS ||  cmdQueue == 0)
         {
               printf("\n\t Failed to create command queue  \n" );
               exit (-1);
         }
        
	/*create kernel object*/
        kernel = clCreateKernel(program,"pieCalculation",&err);
        OPENCL_CHECK_STATUS("error while creating kernel",err);
        
	/*create buffer*/
	d_area = clCreateBuffer(context,CL_MEM_WRITE_ONLY , sizeof(cl_float), NULL, &err);
	OPENCL_CHECK_STATUS("error while creating buffer for devc_area",err);
	d_numOfIntervals = clCreateBuffer(context,CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR , sizeof(cl_int), (void*)&numOfIntervals, &err);	
	OPENCL_CHECK_STATUS("error while creating buffer for devc_area",err);

	/*set kernel arg*/
	err= clSetKernelArg( kernel,0,sizeof(cl_mem),(void *) &d_numOfIntervals);
        OPENCL_CHECK_STATUS("error while setting arg 0",err);
        err = clSetKernelArg(kernel,1,sizeof(cl_mem),(void *) &d_area);
        OPENCL_CHECK_STATUS("error while setting arg 1",err);
        
	/*load kernel*/
        err = clEnqueueNDRangeKernel(cmdQueue,kernel,1,NULL,globalWorkSize,NULL,0,NULL,&gpuExec[0]);
        OPENCL_CHECK_STATUS("error while creating ND range",err);
        
	//completion of all commands to command queue
        err = clFinish(cmdQueue);
        OPENCL_CHECK_STATUS("clFinish",err);

	/* calculate start time and end time*/
        clGetEventProfilingInfo(gpuExec[0], CL_PROFILING_COMMAND_START, sizeof(cl_ulong), &startTime, NULL);
        clGetEventProfilingInfo(gpuExec[0], CL_PROFILING_COMMAND_END, sizeof(cl_ulong), &endTime, NULL);

	/* total elapsed time*/
        elapsedTime = endTime-startTime;

	/*total execution time*/
        executionTimeInSeconds = (float)(1.0e-9 * elapsedTime);
	
	/* reading buffer object*/
        err = clEnqueueReadBuffer(cmdQueue,d_area,CL_TRUE,0,sizeof(cl_float),finalPieValue,0,0,&events);
        OPENCL_CHECK_STATUS("error while reading buffer",err);

	printf("\n\t\tPI value%f",(*finalPieValue));	

        // Print the gflops on the screen
         print_on_screen("Pie calculation-global memory using SP",executionTimeInSeconds,numOfIntervals,gflops,0);

	//release opencl objects
	clReleaseMemObject(d_area);
	clReleaseMemObject(d_numOfIntervals);
	clReleaseProgram(program);
	clReleaseKernel(kernel);
	clReleaseCommandQueue(cmdQueue);
	clReleaseContext(context);
}
/**************************************************************
function to calculate Matrix Infinity norm
*************************************************************/
void    matInfinityNormGMSP(cl_uint numDevices,cl_device_id *devices, cl_program program,cl_context context,float * h_Mat, int *h_Rowcol, float *h_InfiNorm,int height,int width)
{
        cl_command_queue        cmdQueue;     // Command Queue  object
        cl_mem                  d_Mat;     //  device input buffer
        cl_mem                  d_Rowcol;     //  device input buffer
        cl_mem                  d_InfiNorm;      // device output buffer
        cl_kernel               kernel;        //  kernel object
        cl_int                  err;            // Holds the error 
        cl_event                events;        // event object
        double                  totalTime=0.0; //holds total time taken for execution
        size_t                  globalWorkSize[1];    // holds global_work size
        size_t                  localWorkSize[1];    // holds local work size
        int                      count;
        char                    dbuff[100];          
        double                  gflops=0.0;             //holds total achieved gflops
	cl_ulong startTime, endTime,elapsedTime; //holds time
	float executionTimeInSeconds;        //holds total execution time
	cl_event gpuExec[1];         // event object

        /* Get device Name */
       err = clGetDeviceInfo(devices[0], CL_DEVICE_NAME, sizeof(dbuff), &dbuff, NULL);
       OPENCL_CHECK_STATUS("Failed  to Get device Name",err);

	/** Create the command queue **/
        cmdQueue = clCreateCommandQueue( context, devices[0], CL_QUEUE_PROFILING_ENABLE, &err);
        if( err != CL_SUCCESS || cmdQueue == 0)
        {
               printf("\n\t Failed to create command queue  \n" );
               exit (-1);
        }
        
        /* create buffers*/
        d_Mat =clCreateBuffer(context,CL_MEM_READ_ONLY|CL_MEM_COPY_HOST_PTR,(height*width)*sizeof(float),h_Mat,&err);
        OPENCL_CHECK_STATUS("Failed to create device input buffer A  ",err);

        
        d_Rowcol =clCreateBuffer(context,CL_MEM_READ_ONLY|CL_MEM_COPY_HOST_PTR,2*sizeof(cl_int),h_Rowcol,&err);
        OPENCL_CHECK_STATUS("Failed to create device input buffer d_rowcol  ",err);

   	 d_InfiNorm = clCreateBuffer ( context, CL_MEM_WRITE_ONLY , sizeof(float),NULL, &err);
        OPENCL_CHECK_STATUS( "Failed to create device output  buffer   ",err);

         // Create the kernel
         kernel = clCreateKernel ( program, "infinityNorm_kernel", &err);
         OPENCL_CHECK_STATUS(" Create kernel failed ",err);

          //  Set the arguments
     	err = clSetKernelArg( kernel, 0, sizeof(cl_mem), (void *) &d_Mat);
     	OPENCL_CHECK_STATUS( "Set  kernel argument 0 failed ",err);
           	
	err = clSetKernelArg( kernel, 1, sizeof(cl_mem), (void *) &d_Rowcol);
        OPENCL_CHECK_STATUS( "Set  kernel argument 1 failed ",err);
        
   	err = clSetKernelArg( kernel, 2, sizeof(cl_mem), (void *) &d_InfiNorm);
        OPENCL_CHECK_STATUS( "Set  kernel argument 2 failed ",err);
           
         //set Global work size and local work size
        globalWorkSize [0]= height   ; // ND Range Size for each kernel launch 

         //launch the kernel
         err=clEnqueueNDRangeKernel(cmdQueue,kernel,1,NULL,globalWorkSize,NULL,0,NULL,&gpuExec[0]);
         OPENCL_CHECK_STATUS( " Kernel launch failed ",err);
	
	//completion of all commands to command queue
	err = clFinish(cmdQueue);
        OPENCL_CHECK_STATUS("clFinish",err);

	//calculate start time and end time
	clGetEventProfilingInfo(gpuExec[0], CL_PROFILING_COMMAND_START, sizeof(cl_ulong), &startTime, NULL);
        clGetEventProfilingInfo(gpuExec[0], CL_PROFILING_COMMAND_END, sizeof(cl_ulong), &endTime, NULL);

	/*calculate total elapsed time*/
 	elapsedTime = endTime-startTime;
	
	/* total execuition time in seconds*/
 	executionTimeInSeconds = (float)(1.0e-9 * elapsedTime);

         //read the result
         err =clEnqueueReadBuffer(cmdQueue,d_InfiNorm,CL_TRUE,0,sizeof(cl_float),h_InfiNorm,0,0,&events);
         OPENCL_CHECK_STATUS(" Read output failed ",err);

	/* calculate gflops*/
        gflops= (1.0e-9 * ((1.0 *height*height) / executionTimeInSeconds));


        // Print the gflops on the screen
	 print_on_screen("Matrix Infinity Norm",executionTimeInSeconds,height,gflops,1);

        //free opencl objects
        if ( kernel )   clReleaseKernel(kernel);
        if ( cmdQueue) clReleaseCommandQueue(cmdQueue);
        if ( events )   clReleaseEvent(events);
	clReleaseMemObject(d_Mat);
        clReleaseMemObject(d_Rowcol);
        clReleaseMemObject(d_InfiNorm);
}
void    matrixTransposeGMSP (cl_uint numDevices,cl_device_id *devices, cl_program program,cl_context context,float * h_Mat, float *h_Output,int height,int width)
{
        cl_int err;
        cl_command_queue cmdQueue;   //holds command queue object
        cl_kernel kernel;               //holds kernel object
        cl_mem d_Mat,d_rows,d_Output;            //holds device input output buffer
	int workgroup=height;
	size_t globalWorkSize[2]={workgroup,workgroup}; //holds global group size
        double                  gflops=0.0;             //holds total achieved gflops
        cl_ulong startTime, endTime,elapsedTime;       //holds time
        float executionTimeInSeconds;                 //holds total execution time
	cl_event                events; 
         cl_event                gpuExec[1];        // events

	//create command queue
        cmdQueue = clCreateCommandQueue(context, devices[0], CL_QUEUE_PROFILING_ENABLE, &err);
        if( err != CL_SUCCESS ||  cmdQueue == 0)
         {
               printf("\n\t Failed to create command queue  \n" );
               exit (-1);
         }

        /*create kernel object*/
        kernel = clCreateKernel(program,"transMatrix",&err);
        OPENCL_CHECK_STATUS("error while creating kernel",err);

        /*create buffer*/

        d_Mat=clCreateBuffer(context,CL_MEM_READ_ONLY|CL_MEM_COPY_HOST_PTR,sizeof(float)*(height*width),h_Mat,&err);
        OPENCL_CHECK_STATUS("error while creating buffer for input",err);
      
	d_rows=clCreateBuffer(context,CL_MEM_READ_ONLY|CL_MEM_COPY_HOST_PTR,sizeof(float),(void *)&height,&err);
        OPENCL_CHECK_STATUS("error while creating buffer for input",err);
        
	d_Output=clCreateBuffer(context,CL_MEM_WRITE_ONLY,sizeof(float)*(height*width),NULL,&err);
        OPENCL_CHECK_STATUS("error while creating buffer for output",err);


        /*set kernel arg*/
        err=clSetKernelArg(kernel,0,sizeof(cl_mem),(void *)&d_Mat);
        OPENCL_CHECK_STATUS("error while setting arg 1",err);

        err=clSetKernelArg(kernel,1,sizeof(cl_mem),(void *)&d_Output);
        OPENCL_CHECK_STATUS("error while setting arg 1",err);

        err=clSetKernelArg(kernel,2,sizeof(cl_mem),(void *)&d_rows);
        OPENCL_CHECK_STATUS("error while setting arg 2",err);

        /*load kernel*/
        err = clEnqueueNDRangeKernel(cmdQueue,kernel,2,NULL,globalWorkSize,NULL,0,NULL,&gpuExec[0]);
        OPENCL_CHECK_STATUS("error while creating ND range",err);

        //completion of all commands to command queue
        err = clFinish(cmdQueue);
        OPENCL_CHECK_STATUS("clFinish",err);

	/* calculate start time and end time*/
        clGetEventProfilingInfo(gpuExec[0], CL_PROFILING_COMMAND_START, sizeof(cl_ulong), &startTime, NULL);
        clGetEventProfilingInfo(gpuExec[0], CL_PROFILING_COMMAND_END, sizeof(cl_ulong), &endTime, NULL);

	/* total alapsed time*/
        elapsedTime = endTime-startTime;
	/* total execution time*/
        executionTimeInSeconds = (float)(1.0e-9 * elapsedTime);

        /* reading buffer object*/
        err = clEnqueueReadBuffer(cmdQueue,d_Output,CL_TRUE,0,sizeof(cl_float)*height*width,h_Output,0,0,&events);
        OPENCL_CHECK_STATUS("error while reading buffer",err);

        // Print the gflops on the screen
         print_on_screen("Matrix Tranpose using global memory",executionTimeInSeconds,height,gflops,0);

	//release opencl objects
        clReleaseMemObject(d_Mat);
        clReleaseMemObject(d_rows);
        clReleaseMemObject(d_Output);
        clReleaseProgram(program);
        clReleaseKernel(kernel);
        clReleaseCommandQueue(cmdQueue);
        clReleaseContext(context);
}
Esempio n. 13
0
int mini_ventana(char *ptr,int n)
{	SDL_Rect pos;
	pos.x=300;pos.y=251;
        SDL_BlitSurface(mini_window,NULL,screen,&pos);
	pos.x=390; pos.y=310;
	SDL_BlitSurface(texto,NULL,screen,&pos);
	pos.x=325; pos.y=385;
	SDL_BlitSurface(boton_aceptar[0],NULL,screen,&pos);
	pos.x+=185;
	SDL_BlitSurface(boton_cancelar[0],NULL,screen,&pos);
	if(n==1)
        {       pos.x=320; pos.y=270;
                SDL_BlitSurface(icon_add,NULL,screen,&pos);
        }
	else if(n==2)
	{	pos.x=320; pos.y=270;
                SDL_BlitSurface(icon_del,NULL,screen,&pos);
	}
	print_on_screen(ptr,370,260,fcolor,font);
	SDL_Flip(screen);		
	int opcion=-1,aux=1,k=0;
	char c[4];
	SDL_Rect text_pos;
	SDL_Event evento;
	while(opcion!=0)
	{	SDL_WaitEvent(&evento);
		if(evento.type==SDL_MOUSEMOTION)
                {       if(posicion_cursor(325,390,385,408,evento.motion.x,evento.motion.y))
                        {       pos.x=325; pos.y=385;
                                SDL_BlitSurface(boton_aceptar[1],NULL,screen,&pos);
                        }
			else if(posicion_cursor(510,580,385,408,evento.motion.x,evento.motion.y))
			{	 pos.x=510;pos.y=385;
                                 SDL_BlitSurface(boton_cancelar[1],NULL,screen,&pos);
			}
			else
			{	pos.x=325; pos.y=385;
        			SDL_BlitSurface(boton_aceptar[0],NULL,screen,&pos);
        			pos.x+=185;
       				 SDL_BlitSurface(boton_cancelar[0],NULL,screen,&pos);
			}
			SDL_Flip(screen);
		}
		else if(evento.type==SDL_MOUSEBUTTONDOWN)
                {       if(posicion_cursor(510,580,385,408,evento.button.x,evento.button.y))
                        {	draw_interface_principal();
        			draw_menu_botones();
				bandera=0;
        			return -1;
			}
			else if(posicion_cursor(325,390,385,408,evento.motion.x,evento.motion.y))
			{	draw_interface_principal();
        			draw_menu_botones();
				bandera=1;
				return k*aux;  
			}      
		}
		else if(evento.type==SDL_KEYDOWN && k<10)
                {       switch(evento.key.keysym.sym)
                        {       case SDLK_MINUS:
				{	aux=-1; break;}
				case SDLK_1:
				{ 	k*=10; k+=1;break;}
				case SDLK_2:
				{	k*=10;k+=2; break;}	
				case SDLK_3:
				{	k*=10; k+=3; break;}
				case SDLK_4:
                                {       k*=10; k+=4; break;}
				case SDLK_5:
                                {      k*=10; k+=5; break;}
				case SDLK_6:
                                {       k*=10; k+=6; break;}
				case SDLK_7:
                                {       k*=10; k+=7; break;}
				case SDLK_8:
                                {       k*=10; k+=8; break;}
				case SDLK_9:
                                {       k*=10; k+=9; break;}
				case SDLK_0:
				{	k*=10; break;}
				
			}				
		}
		if(evento.type==SDL_KEYDOWN && evento.key.keysym.sym==8)
			k/=10;
		else if(evento.type==SDL_KEYDOWN && evento.key.keysym.sym==SDLK_RETURN)
		{	draw_interface_principal();
                        draw_menu_botones();
                        bandera=1;
                        return k*aux;
		}
		else if(evento.type==SDL_KEYDOWN && evento.key.keysym.sym==27)
		{	draw_interface_principal();
                        draw_menu_botones();
                        bandera=0;
                        return -1;
		}
		text_pos.x=390; text_pos.y=310;
       		SDL_BlitSurface(texto,NULL,screen,&text_pos);
		sprintf(c,"%d",k*aux);
		print_on_screen(&c[0],410,310,fcolor,font_num);		
		SDL_Flip(screen);
	}
}
Esempio n. 14
0
void ventana_recorridos()
{	SDL_Rect pos;
	char c[40];
	pos.x=300; pos.y=251;
	SDL_BlitSurface(mini_window,NULL,screen,&pos);
	sprintf(c,"Recorridos :");
	print_on_screen(&c[0],370,260,fcolor,font);
	pos.x+=110;pos.y+=50;
	SDL_BlitSurface(tipos_recorridos[0][0],NULL,screen,&pos);
	pos.y+=30;
	SDL_BlitSurface(tipos_recorridos[1][0],NULL,screen,&pos);
	pos.y+=30;
	SDL_BlitSurface(tipos_recorridos[2][0],NULL,screen,&pos);
	pos.x+=119;pos.y+=34;
	SDL_BlitSurface(boton_cancelar[0],NULL,screen,&pos);
	SDL_Flip(screen);
	int n=1;
	SDL_Event evento;
	while(n)
	{	SDL_WaitEvent(&evento);
                if(evento.type==SDL_MOUSEMOTION)
		{	if(posicion_cursor(410,410+tipos_recorridos[0][0]->w,301,301+tipos_recorridos[0][0]->h,evento.motion.x,evento.motion.y))
			{	pos.x=410; pos.y=301;
				SDL_BlitSurface(tipos_recorridos[0][1],NULL,screen,&pos);
			}
			else if(posicion_cursor(410,410+tipos_recorridos[1][0]->w,331,331+tipos_recorridos[1][0]->h,evento.motion.x,evento.motion.y))
			{	pos.x=410; pos.y=331,
				SDL_BlitSurface(tipos_recorridos[1][1],NULL,screen,&pos);
			}
			else if(posicion_cursor(410,410+tipos_recorridos[1][0]->w,361,361+tipos_recorridos[1][0]->h,evento.motion.x,evento.motion.y))
			{	pos.x=410; pos.y=361;
				SDL_BlitSurface(tipos_recorridos[2][1],NULL,screen,&pos);
			}
			else if(posicion_cursor(529,529+boton_cancelar[0]->w,395,395+boton_cancelar[0]->h,evento.motion.x,evento.motion.y))
			{	pos.x=529; pos.y=395;
				SDL_BlitSurface(boton_cancelar[1],NULL,screen,&pos);
			}
			else
			{	pos.x=410; pos.y=301;
                                SDL_BlitSurface(tipos_recorridos[0][0],NULL,screen,&pos);
				pos.x=410; pos.y=331,
                                SDL_BlitSurface(tipos_recorridos[1][0],NULL,screen,&pos);
				pos.x=410; pos.y=361;
                                SDL_BlitSurface(tipos_recorridos[2][0],NULL,screen,&pos);
				pos.x=529; pos.y=395;
                                SDL_BlitSurface(boton_cancelar[0],NULL,screen,&pos);

			}
			SDL_Flip(screen);
		}
		else if(evento.type==SDL_MOUSEBUTTONDOWN)
                {       if(posicion_cursor(410,410+tipos_recorridos[0][0]->w,301,301+tipos_recorridos[0][0]->h,evento.button.x,evento.button.y))
                        {	draw_interface_principal();
                                print_arbol(A,0);
				SDL_Rect recta_pos={0,600,900,80};
				SDL_FillRect(screen,&recta_pos,SDL_MapRGBA(screen->format,183,181,182,0));				
				char c[40];
				sprintf(c,"Recorrido Inorder :");
				print_on_screen(&c[0],30,600,fcolor,font_op);distancia=0;
				SDL_Flip(screen);
				inorden(A);
				return;
			}
			else if(posicion_cursor(410,410+tipos_recorridos[1][0]->w,331,331+tipos_recorridos[1][0]->h,evento.button.x,evento.button.y))
			{	draw_interface_principal();
                                print_arbol(A,0);
                                SDL_Rect recta_pos={0,600,900,80};
                                SDL_FillRect(screen,&recta_pos,SDL_MapRGBA(screen->format,183,181,182,0));
                                char c[40];
                                sprintf(c,"Recorrido Preorder :");
                                print_on_screen(&c[0],30,600,fcolor,font_op);distancia=0;
                                SDL_Flip(screen);
				preorden(A);
                                return;
			}
			else if(posicion_cursor(410,410+tipos_recorridos[1][0]->w,361,361+tipos_recorridos[1][0]->h,evento.button.x,evento.button.y))
			{	draw_interface_principal();
                                print_arbol(A,0);
                                SDL_Rect recta_pos={0,600,900,80};
                                SDL_FillRect(screen,&recta_pos,SDL_MapRGBA(screen->format,183,181,182,0));
                                char c[40];
                                sprintf(c,"Recorrido Posorder :");
                                print_on_screen(&c[0],30,600,fcolor,font_op);distancia=0;
                                SDL_Flip(screen);
				postorden(A);
                                return;
			}
			else if(posicion_cursor(529,529+boton_cancelar[0]->w,395,395+boton_cancelar[0]->h,evento.button.x,evento.button.y))
			{	draw_interface_principal();
                                print_arbol(A,0);
                                SDL_Flip(screen);
                                return;
			}
		}
		else if(evento.type==SDL_KEYDOWN && evento.key.keysym.sym==27)
                {       draw_interface_principal();
                        draw_menu_botones();
			print_arbol(A,0);
			SDL_Flip(screen);
			return;
		}
	}
	SDL_Flip(screen);
}
Esempio n. 15
0
void    vectorVectorAdditionGMDP (cl_uint numDevices,cl_device_id *devices, cl_program program,cl_context context,double * h_VectA,double *h_VectB, double *h_Output,int vectSize)
{
	cl_event                gpuExec[1];
        cl_int err;	
	cl_command_queue cmdQueue;   //holds command queue object
	cl_kernel kernel;		//holds kernel object
	cl_mem d_VectA,d_VectB,d_Output;		//holds device input output buffer
	 cl_event                events;        // events
	size_t globalWorkSize[2]={vectSize,vectSize}; //holds global group size

	 double                  gflops=0.0;             //holds total achieved gflops
        cl_ulong startTime, endTime,elapsedTime;        //holds time
        float executionTimeInSeconds;                    //holds total execution time

	  
    	/*create command queue*/
        cmdQueue = clCreateCommandQueue(context, devices[0],  CL_QUEUE_PROFILING_ENABLE, &err);
        if( err != CL_SUCCESS ||  cmdQueue == 0)
         {
               printf("\n\t Failed to create command queue  \n" );
               exit (-1);
         }
        
	/*create kernel object*/
        kernel = clCreateKernel(program,"VectVectAddDPKernel",&err);
        OPENCL_CHECK_STATUS("error while creating kernel",err);
        
	/*create buffer*/
       d_VectA=clCreateBuffer(context,CL_MEM_READ_ONLY|CL_MEM_COPY_HOST_PTR,sizeof(double)*vectSize,h_VectA,&err);
        OPENCL_CHECK_STATUS("error while creating buffer for input",err);
        
       d_VectB=clCreateBuffer(context,CL_MEM_READ_ONLY|CL_MEM_COPY_HOST_PTR,sizeof(double)*vectSize,h_VectB,&err);
        OPENCL_CHECK_STATUS("error while creating buffer for input",err);
        
	d_Output=clCreateBuffer(context,CL_MEM_WRITE_ONLY,sizeof(double)*vectSize,NULL,&err);
        OPENCL_CHECK_STATUS("error while creating buffer for d_Output",err);
        
	/*set kernel arg*/
        err=clSetKernelArg(kernel,0,sizeof(cl_mem),&d_VectA);
        OPENCL_CHECK_STATUS("error while setting arg 0",err);
        
	err=clSetKernelArg(kernel,1,sizeof(cl_mem),&d_VectB);
        OPENCL_CHECK_STATUS("error while setting arg 1",err);
        
	err=clSetKernelArg(kernel,2,sizeof(cl_mem),&d_Output);
        OPENCL_CHECK_STATUS("error while setting arg 2",err);
        
	/*load kernel*/
        err = clEnqueueNDRangeKernel(cmdQueue,kernel,2,NULL,globalWorkSize,NULL,0,NULL,&gpuExec[0]);
        OPENCL_CHECK_STATUS("error while creating ND range",err);
        
	//completion of all commands to command queue
        err = clFinish(cmdQueue);
        OPENCL_CHECK_STATUS("clFinish",err);

	/* calculate start time and end time*/
        clGetEventProfilingInfo(gpuExec[0], CL_PROFILING_COMMAND_START, sizeof(cl_ulong), &startTime, NULL);
        clGetEventProfilingInfo(gpuExec[0], CL_PROFILING_COMMAND_END, sizeof(cl_ulong), &endTime, NULL);


	/* total elapsed time*/
        elapsedTime = endTime-startTime;

	/*total execution time*/
        executionTimeInSeconds = (float)(1.0e-9 * elapsedTime);


	
	/* reading buffer object*/
        err = clEnqueueReadBuffer(cmdQueue,d_Output,CL_TRUE,0,sizeof(cl_double)*vectSize,h_Output,0,0,&events);
        OPENCL_CHECK_STATUS("error while reading buffer",err);
	
	
	/* calculate total gflops*/
         gflops= (1.0e-9 * (( vectSize) / executionTimeInSeconds));


        // Print the gflops on the screen
         print_on_screen("Vector Vector Addition double precision using global memory",executionTimeInSeconds,vectSize,gflops,1);


	//check results 
	vectVectAddCheckResultGMDP(h_VectA,h_VectB,h_Output,vectSize);

	//release opencl objects
	clReleaseMemObject(d_VectA);
	clReleaseMemObject(d_VectB);
	clReleaseMemObject(d_Output);
	clReleaseProgram(program);
	clReleaseKernel(kernel);
	clReleaseCommandQueue(cmdQueue);
	clReleaseContext(context);
}