Exemple #1
0
int
readobjnum( void )
{
  int 	ch     = getc( f );
  int 	nflag  = (ch & NFLAG) != 0;
  int 	r      = ch & 0x3f;

  
  if (ch == EOF)
    {
      inform( "Error - Unexpected EOF" );

      tidyup( 1 );
    }
  
   while ((ch & MORE) != 0)
     {
       if ((ch = getc( f )) == EOF)
	 {
	   inform( "Error - Unexpected EOF" );
	   
	   tidyup( 1 );
	 }

       r  = (r << 7) + (ch & 0x7f);
     }

  return nflag ? -r : r;

} /* readobjnum */
Exemple #2
0
int
main( int	argc,
     char *	argv[] )
{
  ProgName = argv[0];
       
  switch (setup ( argc, argv ))
    {
    default:
    case SYSBUILD_FAIL: break;
    case SYSBUILD_OK:
      parse_config_file (ConfigData.config_file);
  
      update_configdata ();
  
      print_configdata ();
  
      if (!ShowOnly)
	{
	  make_nucleus ();
  
	  check_bootstrap ();
  
	  output_image ();
	}
      
      break;
      
    case SYSBUILD_OLD:
      sysbuild( argc, argv );
      break;
    }
    
  tidyup ();
}
Exemple #3
0
void sysbuild_error (char *	fmt,
		    ...)
{
	va_list	args;

	va_start (args, fmt);

	if (ErrorsEnabled)
	{
		fprintf (stderr, "%s - Error: ", ProgName);

		vfprintf (stderr, fmt, args);
	
		fprintf (stderr, "\n");

		tidyup ();

		va_end (args);

		exit (SYSBUILDERR_FAIL);
	}
	else if (WarningsEnabled)
	{
		fprintf (stderr, "%s - Warning: ", ProgName);

		va_start (args, fmt);

		vfprintf (stderr, fmt, args);

		fprintf (stderr, "\n");
	}

	va_end (args);
}
Exemple #4
0
void constants_init(int argc, char **argv)
{
	init_config("cons.txt");
	POP_SIZE = atoi(getvalue("POP_SIZE"));
	if(strcmp(getvalue("POP_INIT"), "false") == 0)
		POP_INIT = false;
	else
		POP_INIT = true;
	NUM_EXPERIMENTS = atoi(getvalue("NUM_EXPERIMENTS"));
	MAX_TRIALS = atoi(getvalue("MAX_TRIALS"));
	P_CROSSOVER = atof(getvalue("P_CROSSOVER"));
	P_MUTATION = atof(getvalue("P_MUTATION"));
	THETA_SUB = atof(getvalue("THETA_SUB"));
	EPS_0 = atof(getvalue("EPS_0"));
	DELTA = atof(getvalue("DELTA"));
	THETA_DEL = atof(getvalue("THETA_DEL"));
	THETA_GA = atof(getvalue("THETA_GA"));
	BETA = atof(getvalue("BETA"));
	ALPHA = atof(getvalue("ALPHA")); 
	NU = atof(getvalue("NU"));
	GAMMA = atof(getvalue("GAMMA"));
	P_DONTCARE = atof(getvalue("P_DONTCARE"));
	DONT_CARE = '#';
	INIT_PREDICTION = atof(getvalue("INIT_PREDICTION"));
	INIT_FITNESS = atof(getvalue("INIT_FITNESS"));
	INIT_ERROR = atof(getvalue("INIT_ERROR"));
	ERR_REDUC = atof(getvalue("ERR_REDUC"));
	FIT_REDUC = atof(getvalue("FIT_REDUC"));
	TELETRANSPORTATION = atoi(getvalue("TELETRANSPORTATION"));
	if(strcmp(getvalue("GA_SUBSUMPTION"), "false") == 0)
		GA_SUBSUMPTION = false;
	else
		GA_SUBSUMPTION = true;
	if(strcmp(getvalue("ACTION_SUBSUMPTION"), "false") == 0)
		ACTION_SUBSUMPTION = false;
	else
		ACTION_SUBSUMPTION = true;
	PERF_AVG_TRIALS = atoi(getvalue("PERF_AVG_TRIALS"));
	XCSF_X0 = atof(getvalue("XCSF_X0"));
	XCSF_ETA = atof(getvalue("XCSF_ETA"));
	muEPS_0 = atof(getvalue("muEPS_0"));
	NUM_MU = atoi(getvalue("NUM_MU"));
	tidyup();
	// override cons.txt with command line arguments
	if(argc > 3) {
		MAX_TRIALS = atoi(argv[3]);
		if(argc > 4)
			NUM_EXPERIMENTS = atoi(argv[4]);
	}      
}
Exemple #5
0
void
usage ( int exit_val )
{
  fprintf (stderr, "usage: %s [-hweDdln] [-c config-file] [-o nucleus]\n", ProgName);
  fprintf (stderr, "		w	Disable warning messages\n");
  fprintf (stderr, "		e	Display errors as warnings\n");
  fprintf (stderr, "		d	Debug information\n");
  fprintf (stderr, "		D	Debug on stdout\n");
  fprintf (stderr, "		l	Long format (display the contents of the nucleus)\n");
  fprintf (stderr, "		n	Display contents of the nucleus, but don't build\n");
  fprintf (stderr, "OR\n");
  fprintf (stderr, "       %s <nucleus-name> {<image-file>}\n", ProgName);

  tidyup ();

  exit (exit_val);
}
Exemple #6
0
void sysbuild_fatal (char *	fmt,
		     ...)
{
	va_list	args;

	va_start (args, fmt);

	fprintf (stderr, "%s - Fatal Error: ", ProgName);

	vfprintf (stderr, fmt, args);
	
	fprintf (stderr, "\n");

	tidyup ();

	va_end (args);

	exit (SYSBUILDERR_FAIL);
}
Exemple #7
0
int main ( int argc, char *argv[])
{
   float sigma, rcut, dt, eqtemp, dens, boxlx, boxly, boxlz, sfx, sfy, sfz, sr6, vrcut, dvrcut, dvrc12, freex; 
   int nstep, nequil, iscale, nc, mx, my, mz, iprint;
   float *rx, *ry, *rz, *vx, *vy, *vz, *fx, *fy, *fz, *potentialPointer, *virialPointer, *virialArray, *potentialArray, *virialArrayTemp, *potentialArrayTemp;
   float ace, acv, ack, acp, acesq, acvsq, acksq, acpsq, vg, kg, wg;
   int   *head, *list;
   int   natoms=0;
   int ierror;
   int jstart, step, itemp;
   float potential, virial, kinetic;
   float tmpx;
   int i, icell;
   cl_int err;

   cl_device_id device;
   cl_context context;
   cl_command_queue queue;
   cl_program program;
   cl_kernel force_kernel;
   cl_kernel add_kernel;

   cl_mem d_rx, d_ry, d_rz, d_fx, d_fy, d_fz, d_head, d_list, d_potential, d_virial, d_virialArray, d_potentialArray;

   ierror = input_parameters (&sigma, &rcut, &dt, &eqtemp, &dens, &boxlx, &boxly, &boxlz, &sfx, &sfy, &sfz, &sr6, &vrcut, &dvrcut, &dvrc12, &freex, &nstep, &nequil, &iscale, &nc, &natoms, &mx, &my, &mz, &iprint);
   //printf ("\nReturned from input_parameters, natoms = %d\n", natoms);
   device = create_device();
   context = clCreateContext(NULL, 1, &device, NULL, NULL, &err);
   if(err < 0) {
     perror("Couldn't create a context");
     exit(1);   
   }
   /* Build the program */
   program = build_program(context, device, PROGRAM_FILE);
   force_kernel = clCreateKernel(program, FORCE_KERNEL, &err);
   if(err < 0) {
     perror("Couldn't create a kernel");
     exit(1);
   }
   //printf("\nmx = %d, my = %d, mz = %d\n",mx,my,mz);
   rx = (float *)malloc(2*natoms*sizeof(float));
   ry = (float *)malloc(2*natoms*sizeof(float));
   rz = (float *)malloc(2*natoms*sizeof(float));
   vx = (float *)malloc(natoms*sizeof(float));
   vy = (float *)malloc(natoms*sizeof(float));
   vz = (float *)malloc(natoms*sizeof(float));
   fx = (float *)malloc(natoms*sizeof(float));
   fy = (float *)malloc(natoms*sizeof(float));
   fz = (float *)malloc(natoms*sizeof(float));
   list = (int *)malloc(2*natoms*sizeof(int));
   head= (int *)malloc((mx+2)*(my+2)*(mz+2)*sizeof(int));
   virialPointer = (float *)malloc(sizeof(float));
   potentialPointer = (float *)malloc(sizeof(float));
   int index = 0;

   int numBlocks = ceil(natoms/(float)BLOCK_WIDTH);
   virialArray = (float *)malloc( (numBlocks)* sizeof(float));
   potentialArray = (float *)malloc((numBlocks) * sizeof(float));
   virialArrayTemp = (float *)malloc(numBlocks * sizeof(float));
   potentialArrayTemp = (float *)malloc(numBlocks * sizeof(float));
   for (index = 0; index < numBlocks; index++)
   {
      virialArray[index] = (float)0;
      potentialArray[index] = (float)0;
   }
  // printf ("\nFinished allocating memory\n");

   initialise_particles (rx, ry, rz, vx, vy, vz, nc);
 //  printf ("\nReturned from initialise_particles\n");

   loop_initialise(&ace, &acv, &ack, &acp, &acesq, &acvsq, &acksq, &acpsq, sigma, rcut, dt);
//   printf ("\nReturned from loop_initialise\n");

//   output_particles(rx,ry,rz,vx,vy,vz,fx,fy,fz,0);
      movout (rx, ry, rz, vx, vy, vz, sfx, sfy, sfz, head, list, mx, my, mz, natoms);
 //  printf ("\nReturned from movout\n");
   //   check_cells(rx, ry, rz, head, list, mx, my, mz, natoms,0,0);
   *potentialPointer = (float)0;
   *virialPointer = (float)0;
   d_rx = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, sizeof(float) * natoms * 2, rx, &err);
   if(err < 0) {
     perror("Couldn't create a command queue");
     exit(1);   
   }   
   d_ry = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, sizeof(float) * natoms * 2, ry, &err);
   if(err < 0) {
     perror("Couldn't create a command queue");
     exit(1);   
   }   
   d_rz = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, sizeof(float) * natoms * 2, rz, &err);
   if(err < 0) {
     perror("Couldn't create a command queue");
     exit(1);   
   }   
   d_fx = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, sizeof(float) * natoms, fx, &err);
   if(err < 0) {
     perror("Couldn't create a command queue");
     exit(1);   
   }   
   d_fy = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, sizeof(float) * natoms, fy, &err);
   if(err < 0) {
     perror("Couldn't create a command queue");
     exit(1);   
   }   
   d_fz = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, sizeof(float) * natoms, fz, &err);
   if(err < 0) {
     perror("Couldn't create a command queue");
     exit(1);   
   }   
   d_head = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, (mx+2)*(my+2)*(mz+2)*sizeof(int), head, &err);
   if(err < 0) {
     perror("Couldn't create a command queue");
     exit(1);   
   }   
   d_list = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, 2*natoms*sizeof(int), list, &err);
   if(err < 0) {
     perror("Couldn't create a command queue");
     exit(1);   
   }   
   d_virialArray = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,  sizeof(float) * (numBlocks), virialArray, &err);
   if(err < 0) {
     perror("Couldn't create a command queue");
     exit(1);   
   }   
   d_potentialArray = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,  sizeof(float) * (numBlocks), potentialArray, &err);
   if(err < 0) {
     perror("Couldn't create a command queue");
     exit(1);   
   }

    
   err = clSetKernelArg(force_kernel, 0, sizeof(cl_mem), &d_virialArray);
   err |= clSetKernelArg(force_kernel, 1, sizeof(cl_mem), &d_potentialArray);
   err |= clSetKernelArg(force_kernel, 2, sizeof(cl_mem), &d_rx);
   err |= clSetKernelArg(force_kernel, 3, sizeof(cl_mem), &d_ry);
   err |= clSetKernelArg(force_kernel, 4, sizeof(cl_mem), &d_rz);
   err |= clSetKernelArg(force_kernel, 5, sizeof(cl_mem), &d_fx);
   err |= clSetKernelArg(force_kernel, 6, sizeof(cl_mem), &d_fy);
   err |= clSetKernelArg(force_kernel, 7, sizeof(cl_mem), &d_fz);
   err |= clSetKernelArg(force_kernel, 8, sizeof(sigma), &sigma);
   err |= clSetKernelArg(force_kernel, 9, sizeof(rcut), &rcut);
   err |= clSetKernelArg(force_kernel, 10, sizeof(vrcut), &vrcut);
   err |= clSetKernelArg(force_kernel, 11, sizeof(dvrc12), &dvrc12);
   err |= clSetKernelArg(force_kernel, 12, sizeof(dvrcut), &dvrcut);
   err |= clSetKernelArg(force_kernel, 13, sizeof(cl_mem), &d_head);
   err |= clSetKernelArg(force_kernel, 14, sizeof(cl_mem), &d_list);
   err |= clSetKernelArg(force_kernel, 15, sizeof(mx), &mx);
   err |= clSetKernelArg(force_kernel, 16, sizeof(my), &my);
   err |= clSetKernelArg(force_kernel, 17, sizeof(mz), &mz);
   err |= clSetKernelArg(force_kernel, 18, sizeof(natoms), &natoms);
   err |= clSetKernelArg(force_kernel, 19, sizeof(sfx), &sfx);
   err |= clSetKernelArg(force_kernel, 20, sizeof(sfy), &sfy);
   err |= clSetKernelArg(force_kernel, 21, sizeof(sfz), &sfz);
   if(err < 0) {
     printf("Couldn't set an argument for the transpose kernel");
     exit(1);   
   }
   //size_t max_size;
   //clGetKernelWorkGroupInfo(add_kernel, device, CL_KERNEL_WORK_GROUP_SIZE, sizeof(max_size), &max_size, NULL);
   //printf("\nMAX SIZE: %d\n", max_size);
   
   queue = clCreateCommandQueue(context, device, 0, &err);
   if(err < 0) {
     perror("Couldn't create a command queue");
     exit(1);   
   }
   size_t global_size[1];
   size_t local_size[1];
   global_size[0] = BLOCK_WIDTH * ceil(natoms / (float) BLOCK_WIDTH);
   local_size[0] = BLOCK_WIDTH;
   long double elapsedTime = (float)0.0;
   long unsigned int startTime;
   long unsigned int endTime;
   

   startTime = get_tick();
   err = clEnqueueNDRangeKernel(queue, force_kernel, 1, NULL, global_size, local_size, 0, NULL, NULL);
   clFinish(queue);
   endTime = get_tick();
   if(err < 0) {
     printf("Couldn't enqueue force kernel\n");
     printf("%d\n", err);
     printf("CL_INVALID_PROGRAM_EXECUTABLE: %d\n", CL_INVALID_PROGRAM_EXECUTABLE);
     printf("CL_INVALID_COMMAND_QUEUE: %d\n",CL_INVALID_COMMAND_QUEUE );
     printf("CL_INVALID_KERNEL: %d\n", CL_INVALID_KERNEL);
     printf("CL_INVALID_CONTEXT: %d\n", CL_INVALID_CONTEXT);
     printf("CL_INVALID_KERNEL_ARGS: %d\n", CL_INVALID_KERNEL_ARGS);
     printf("CL_INVALID_WORK_DIMENSION: %d\n", CL_INVALID_WORK_DIMENSION);
     printf("CL_INVALID_GLOBAL_WORK_SIZE: %d\n", CL_INVALID_GLOBAL_WORK_SIZE);
     printf("CL_INVALID_GLOBAL_OFFSET: %d\n", CL_INVALID_GLOBAL_OFFSET);
     printf("CL_INVALID_WORK_GROUP_SIZE: %d\n", CL_INVALID_WORK_GROUP_SIZE);
     exit(1);   
   }
   elapsedTime += endTime - startTime;
   err = clEnqueueReadBuffer(queue, d_fx, CL_TRUE, 0, sizeof(float) * natoms, fx, 0, NULL, NULL);
   err |= clEnqueueReadBuffer(queue, d_fy, CL_TRUE, 0, sizeof(float) * natoms, fy, 0, NULL, NULL);
   err |= clEnqueueReadBuffer(queue, d_fz, CL_TRUE, 0, sizeof(float) * natoms, fz, 0, NULL, NULL);
   err |= clEnqueueReadBuffer(queue, d_virialArray, CL_TRUE, 0, sizeof(float) * numBlocks, virialArrayTemp, 0, NULL, NULL);
   err |= clEnqueueReadBuffer(queue, d_potentialArray, CL_TRUE, 0, sizeof(float) * numBlocks, potentialArrayTemp, 0, NULL, NULL);
   if(err < 0) {
     printf("Couldn't read fx buffer\n");
     printf("%d\n",err );
     printf("CL_INVALID_COMMAND_QUEUE: %d\n",CL_INVALID_COMMAND_QUEUE);
     printf("CL_INVALID_CONTEXT: %d\n", CL_INVALID_CONTEXT);
     printf("CL_INVALID_MEM_OBJECT: %d\n", CL_INVALID_MEM_OBJECT);
     printf("CL_INVALID_VALUE: %d\n",CL_INVALID_VALUE);
     printf("CL_INVALID_EVENT_WAIT_LIST: %d\n", CL_INVALID_EVENT_WAIT_LIST);
     printf("CL_MEM_OBJECT_ALLOCATION_FAILURE: %d\n",CL_MEM_OBJECT_ALLOCATION_FAILURE);
     printf("CL_OUT_OF_HOST_MEMORY: %d\n", CL_OUT_OF_HOST_MEMORY);
     exit(1);   
   }
   clFinish(queue);
   virial = 0.0;
   potential = 0.0;
   int tempInd = 0;
   for (tempInd =0; tempInd < numBlocks; tempInd++)
   {
      potential += potentialArrayTemp[tempInd];
      virial += virialArrayTemp[tempInd];
   }
   virial *= 48.0/3.0;
   potential *= 4.0;

  // printf ("\nReturned from force: potential = %f, virial = %f, kinetic = %f\n",potential, virial, kinetic);
//   output_particles(rx,ry,rz,vx,vy,vz,fx,fy,fz,0);


   for(step=1;step<=nstep;step++){
     // if(step>=85)printf ("\nStarted step %d\n",step);
      movea (rx, ry, rz, vx, vy, vz, fx, fy, fz, dt, natoms);
//      check_cells(rx, ry, rz, head, list, mx, my, mz, natoms,step,step);
    //  if(step>85)printf ("\nReturned from movea\n");
      movout (rx, ry, rz, vx, vy, vz, sfx, sfy, sfz, head, list, mx, my, mz, natoms);
   //  if(step>85) printf ("\nReturned from movout\n");
  //    check_cells(rx, ry, rz, head, list, mx, my, mz, natoms,step,step);
      clReleaseMemObject(d_rx);
      clReleaseMemObject(d_ry);
      clReleaseMemObject(d_rz);
      clReleaseMemObject(d_fx);
      clReleaseMemObject(d_fy);
      clReleaseMemObject(d_fz);
      clReleaseMemObject(d_head);
      clReleaseMemObject(d_list);
      clReleaseMemObject(d_virialArray);
      clReleaseMemObject(d_potentialArray);
   d_rx = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, sizeof(float) * natoms * 2, rx, &err);
   if(err < 0) {
     perror("Couldn't create a command queue");
     exit(1);   
   }   
   d_ry = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, sizeof(float) * natoms * 2, ry, &err);
   if(err < 0) {
     perror("Couldn't create a command queue");
     exit(1);   
   }   
   d_rz = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, sizeof(float) * natoms * 2, rz, &err);
   if(err < 0) {
     perror("Couldn't create a command queue");
     exit(1);   
   }   
   d_fx = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, sizeof(float) * natoms, fx, &err);
   if(err < 0) {
     perror("Couldn't create a command queue");
     exit(1);   
   }   
   d_fy = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, sizeof(float) * natoms, fy, &err);
   if(err < 0) {
     perror("Couldn't create a command queue");
     exit(1);   
   }   
   d_fz = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, sizeof(float) * natoms, fz, &err);
   if(err < 0) {
     perror("Couldn't create a command queue");
     exit(1);   
   }   
   d_head = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, (mx+2)*(my+2)*(mz+2)*sizeof(int), head, &err);
   if(err < 0) {
     perror("Couldn't create a command queue");
     exit(1);   
   }   
   d_list = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, 2*natoms*sizeof(int), list, &err);
   if(err < 0) {
     perror("Couldn't create a command queue");
     exit(1);   
   }    
   d_virialArray = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,  sizeof(float) * (numBlocks), virialArray, &err);
   if(err < 0) {
     perror("Couldn't create a command queue");
     exit(1);   
   }   
   d_potentialArray = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,  sizeof(float) * (numBlocks), potentialArray, &err);
   if(err < 0) {
     perror("Couldn't create a command queue");
     exit(1);   
   }    
    
   err = clSetKernelArg(force_kernel, 0, sizeof(cl_mem), &d_virialArray);
   err |= clSetKernelArg(force_kernel, 1, sizeof(cl_mem), &d_potentialArray);
   err |= clSetKernelArg(force_kernel, 2, sizeof(cl_mem), &d_rx);
   err |= clSetKernelArg(force_kernel, 3, sizeof(cl_mem), &d_ry);
   err |= clSetKernelArg(force_kernel, 4, sizeof(cl_mem), &d_rz);
   err |= clSetKernelArg(force_kernel, 5, sizeof(cl_mem), &d_fx);
   err |= clSetKernelArg(force_kernel, 6, sizeof(cl_mem), &d_fy);
   err |= clSetKernelArg(force_kernel, 7, sizeof(cl_mem), &d_fz);
   err |= clSetKernelArg(force_kernel, 8, sizeof(sigma), &sigma);
   err |= clSetKernelArg(force_kernel, 9, sizeof(rcut), &rcut);
   err |= clSetKernelArg(force_kernel, 10, sizeof(vrcut), &vrcut);
   err |= clSetKernelArg(force_kernel, 11, sizeof(dvrc12), &dvrc12);
   err |= clSetKernelArg(force_kernel, 12, sizeof(dvrcut), &dvrcut);
   err |= clSetKernelArg(force_kernel, 13, sizeof(cl_mem), &d_head);
   err |= clSetKernelArg(force_kernel, 14, sizeof(cl_mem), &d_list);
   err |= clSetKernelArg(force_kernel, 15, sizeof(mx), &mx);
   err |= clSetKernelArg(force_kernel, 16, sizeof(my), &my);
   err |= clSetKernelArg(force_kernel, 17, sizeof(mz), &mz);
   err |= clSetKernelArg(force_kernel, 18, sizeof(natoms), &natoms);
   err |= clSetKernelArg(force_kernel, 19, sizeof(sfx), &sfx);
   err |= clSetKernelArg(force_kernel, 20, sizeof(sfy), &sfy);
   err |= clSetKernelArg(force_kernel, 21, sizeof(sfz), &sfz);

   if(err < 0) {
     printf("Couldn't set an argument for the transpose kernel");
     exit(1);   
   }


      global_size[0] = BLOCK_WIDTH * ceil(natoms / (float) BLOCK_WIDTH);
      local_size[0] = BLOCK_WIDTH;
      //printf("Global Size: %d\n", global_size[0]);
      //printf("Local Size: %d\n", local_size[0]);
      clFinish(queue);
      startTime = get_tick();
      err = clEnqueueNDRangeKernel(queue, force_kernel, 1, NULL, global_size, local_size, 0, NULL, NULL);
      clFinish(queue);
      endTime = get_tick();
      elapsedTime += endTime - startTime;
      if(err < 0) {
        printf("Couldn't enqueue force kernel\n");
        exit(1);   
      }
      //float fxTest[natoms];
      //size_t sizy = sizeof(float) * (natoms);
      err = clEnqueueReadBuffer(queue, d_fx, CL_TRUE, 0, sizeof(float) * natoms, fx, 0, NULL, NULL);
      err |= clEnqueueReadBuffer(queue, d_fy, CL_TRUE, 0, sizeof(float) * natoms, fy, 0, NULL, NULL);
      err |= clEnqueueReadBuffer(queue, d_fz, CL_TRUE, 0, sizeof(float) * natoms, fz, 0, NULL, NULL);
      err |= clEnqueueReadBuffer(queue, d_virialArray, CL_TRUE, 0, sizeof(float) * numBlocks, virialArrayTemp, 0, NULL, NULL);
      err |= clEnqueueReadBuffer(queue, d_potentialArray, CL_TRUE, 0, sizeof(float) * numBlocks, potentialArrayTemp, 0, NULL, NULL);
      if(err < 0) {
        printf("Couldn't read buffer\n");
        printf("%d\n",err );
        printf("CL_INVALID_COMMAND_QUEUE: %d\n",CL_INVALID_COMMAND_QUEUE);
        printf("CL_INVALID_CONTEXT: %d\n", CL_INVALID_CONTEXT);
        printf("CL_INVALID_MEM_OBJECT: %d\n", CL_INVALID_MEM_OBJECT);
        printf("CL_INVALID_VALUE: %d\n",CL_INVALID_VALUE);
        printf("CL_INVALID_EVENT_WAIT_LIST: %d\n", CL_INVALID_EVENT_WAIT_LIST);
        printf("CL_MEM_OBJECT_ALLOCATION_FAILURE: %d\n",CL_MEM_OBJECT_ALLOCATION_FAILURE);
        printf("CL_OUT_OF_HOST_MEMORY: %d\n", CL_OUT_OF_HOST_MEMORY);
        exit(1);   
      }
      clFinish(queue);
      //numInc = 0;
      //globalThreads = ceil(numBlocks / (float)BLOCK_WIDTH);
     // startTime = get_tick();
      virial = 0.0;
      potential = 0.0;
      int tempInd = 0;
      for (tempInd =0; tempInd < numBlocks; tempInd++)
      {
        potential += potentialArrayTemp[tempInd];
        virial += virialArrayTemp[tempInd];
      }
      virial *= 48.0/3.0;
      potential *= 4.0;

//      if(step>85)printf ("\nReturned from force: potential = %f, virial = %f, kinetic = %f\n",potential, virial, kinetic);
 //     fflush(stdout);
      moveb (&kinetic, vx, vy, vz, fx, fy, fz, dt, natoms);
 //     check_cells(rx, ry, rz, head, list, mx, my, mz, natoms,step,step);
  // if(step>85)   printf ("\nReturned from moveb: potential = %f, virial = %f, kinetic = %f\n",potential, virial, kinetic);
      sum_energies (potential, kinetic, virial, &vg, &wg, &kg);
      hloop (kinetic, step, vg, wg, kg, freex, dens, sigma, eqtemp, &tmpx, &ace, &acv, &ack, &acp, &acesq, &acvsq, &acksq, &acpsq, vx, vy, vz, iscale, iprint, nequil, natoms);

   }

   tidyup (ace, ack, acv, acp, acesq, acksq, acvsq, acpsq, nstep, nequil);
   elapsedTime = elapsedTime / (float) 1000;
   printf("\n%Lf seconds have elapsed\n", elapsedTime);
   
   return 0;
}
Exemple #8
0
int main ( int argc, char *argv[])
{
   float sigma, rcut, dt, eqtemp, dens, boxlx, boxly, boxlz, sfx, sfy, sfz, sr6, vrcut, dvrcut, dvrc12, freex; 
   int nstep, nequil, iscale, nc, mx, my, mz, iprint, map[MAPSIZ];
   float *rx, *ry, *rz, *vx, *vy, *vz, *fx, *fy, *fz;
   float ace, acv, ack, acp, acesq, acvsq, acksq, acpsq, vg, kg, wg;
   int   *head, *list;
   int   natoms=0;
   int ierror;
   int jstart, step, itemp;
   float potential, virial, kinetic;
   float tmpx;
   int i, icell;

   ierror = input_parameters (&sigma, &rcut, &dt, &eqtemp, &dens, &boxlx, &boxly, &boxlz, &sfx, &sfy, &sfz, &sr6, &vrcut, &dvrcut, &dvrc12, &freex, &nstep, &nequil, &iscale, &nc, &natoms, &mx, &my, &mz, &iprint, map);
   //printf ("\nReturned from input_parameters, natoms = %d\n", natoms);

   rx = (float *)malloc(2*natoms*sizeof(float));
   ry = (float *)malloc(2*natoms*sizeof(float));
   rz = (float *)malloc(2*natoms*sizeof(float));
   vx = (float *)malloc(natoms*sizeof(float));
   vy = (float *)malloc(natoms*sizeof(float));
   vz = (float *)malloc(natoms*sizeof(float));
   fx = (float *)malloc(natoms*sizeof(float));
   fy = (float *)malloc(natoms*sizeof(float));
   fz = (float *)malloc(natoms*sizeof(float));
   list = (int *)malloc(2*natoms*sizeof(int));
   head = (int *)malloc((mx+2)*(my+2)*(mz+2)*sizeof(int));

   initialise_particles (rx, ry, rz, vx, vy, vz, nc);
   //printf ("\nReturned from initialise_particles\n");

   loop_initialise(&ace, &acv, &ack, &acp, &acesq, &acvsq, &acksq, &acpsq, sigma, rcut, dt);
   //printf ("\nReturned from loop_initialise\n");

   output_particles(rx,ry,rz,vx,vy,vz,fx,fy,fz,0);
      movout (rx, ry, rz, vx, vy, vz, sfx, sfy, sfz, head, list, mx, my, mz, natoms);
   //printf ("\nReturned from movout\n");
   //   check_cells(rx, ry, rz, head, list, mx, my, mz, natoms,0,0);
      force (&potential, &virial, rx, ry, rz, fx, fy, fz, sigma, rcut, vrcut, dvrc12, dvrcut, head, list, map, mx, my, mz, natoms,0);
   //printf ("\nReturned from force: potential = %f, virial = %f, kinetic = %f\n",potential, virial, kinetic);
   output_particles(rx,ry,rz,vx,vy,vz,fx,fy,fz,0);


   for(step=1;step<=nstep;step++){
   //printf ("\nStarted step %d\n",step);
      movea (rx, ry, rz, vx, vy, vz, fx, fy, fz, dt, natoms);
//      check_cells(rx, ry, rz, head, list, mx, my, mz, natoms,step,step);
   //printf ("\nReturned from movea\n");
      movout (rx, ry, rz, vx, vy, vz, sfx, sfy, sfz, head, list, mx, my, mz, natoms);
  // printf ("\nReturned from movout\n");
  //    check_cells(rx, ry, rz, head, list, mx, my, mz, natoms,step,step);
      force (&potential, &virial, rx, ry, rz, fx, fy, fz, sigma, rcut, vrcut, dvrc12, dvrcut, head, list, map, mx, my, mz, natoms, step);
   //printf ("\nReturned from force: potential = %f, virial = %f, kinetic = %f\n",potential, virial, kinetic);
      moveb (&kinetic, vx, vy, vz, fx, fy, fz, dt, natoms);
 //     check_cells(rx, ry, rz, head, list, mx, my, mz, natoms,step,step);
//   printf ("\nReturned from moveb: potential = %f, virial = %f, kinetic = %f\n",potential, virial, kinetic);
      sum_energies (potential, kinetic, virial, &vg, &wg, &kg);
      hloop (kinetic, step, vg, wg, kg, freex, dens, sigma, eqtemp, &tmpx, &ace, &acv, &ack, &acp, &acesq, &acvsq, &acksq, &acpsq, vx, vy, vz, iscale, iprint, nequil, natoms);
   }

   tidyup (ace, ack, acv, acp, acesq, acksq, acvsq, acpsq, nstep, nequil);
   
   return 0;
}
Exemple #9
0
int main(int argc, char* argv[])
{
	int ret;
	char fn[32] = "/sdcard/car.config";

	if(atexit(exit_handler) != 0) {
		exit(EXIT_FAILURE);
	}

	if(signal(SIGINT, signal_init_handler) == SIG_ERR) {
		exit(EXIT_FAILURE);
	}

	i2c_download_adv7180_init();
	

	int width = 320;
	int height = 240;


	config.width = width;
	config.height = height;
	config.format = V4L2_PIX_FMT_YUV420;
	//config.format = V4L2_PIX_FMT_YUV422P;


	tvout_open(&config);

	fd_mem  = open( "/dev/mem", O_RDWR ); 
//	paddr_mem_tv = mmap( 0, size_mem, PROT_READ | PROT_WRITE, MAP_SHARED, fd_mem, addr_phy_tv );
//	memset(paddr_mem_tv, 0x80, size_mem);
	size_mem = width * height * 2;
	paddr_mem_tv = mmap( 0, size_mem, PROT_READ | PROT_WRITE, MAP_SHARED, fd_mem, addr_phy_tv );
	memset(paddr_mem_tv, 0x80, size_mem);


	camera.format.width = width;                            /* set output frame width */
	camera.format.height = height;                          /* set output frame height */
	camera.format.pixelformat = V4L2_PIX_FMT_YUV420;
	//camera.format.pixelformat = V4L2_PIX_FMT_YUYV;

	ret = camera_init(&camera);
	if(0 > ret) {
		perror("open camera device error");
		exit(EXIT_FAILURE);
	}

	unsigned char *paddr_camera;
	long	size_camera;

	struct timeval start,end;
	long timeuse = 0;
	long time_max = 0;
	long time_temp = 0;
	int i = 0;

	static struct car_parm_setting car_set;

	if(initlib(fn) >= 0) {
		if (isname("PARAM","carbody_width"))
			car_set.carbody_width = atoi(getvalue("carbody_width"));
		if (isname("PARAM","camera_high_degree"))
			car_set.camera_high_degree = atoi(getvalue("camera_high_degree"));
		tidyup();
	}
	else {
		car_set.carbody_width = 150;
		car_set.camera_high_degree = 50;
	}

	car_set.init_flag = 1;
	car_set.img_width = width;
	car_set.img_height = height;

	printf("/*......Car Setting......*/\n");
	printf("  carbody width = %d cm \n", car_set.carbody_width);
	printf("  camera high degree = %d cm \n", car_set.camera_high_degree);
	printf("  image width = %d pixel \n", car_set.img_width);
	printf("  image height = %d pixel \n", car_set.img_height);
	printf("/*.......................*/\n");


	while (1) {

//		paddr_camera = camera_get_one_frame_noneblock(&camera, &size_camera);
//
		gettimeofday( &start, NULL );

		paddr_camera = camera_get_one_frame(&camera, &size_camera);
		car_set.pIn_addr = paddr_camera;
		car_set.gps_speed = 70;
		car_set.light_signal = LIGHT_SIGNAL_OFF;

		paddr_camera = set_car_parm(&car_set);
		switch(car_set.car_event) {
			case WARNING_DRIVING_SAFE:
				printf("=\n");
				break;
			case WARNING_DRIVING_LEFT:
				printf("<\n");
				break;
			case WARNING_DRIVING_RIGHT:
				printf(">\n");
				break;
		}

		//car_event = car_set.car_event;
		paddr_camera = car_set.pOut_addr;

		memcpy(paddr_mem_tv, paddr_camera, width*height); 
		camera_get_one_frame_complete(&camera);

		config.addr_phy = addr_phy_tv;
		tvout_exe(&config);


		gettimeofday( &end, NULL );
		time_temp = 1000000 * ( end.tv_sec - start.tv_sec )+ (end.tv_usec - start.tv_usec);
		if (time_temp > time_max) {
			time_max = time_temp;
		}
		timeuse +=time_temp;
		DEBUG("time used: % 7ld us\n", time_temp);


		++i;
		if ( timeuse > 10*1000000) {
			printf("get %d frames spent % 7ld msec  average frame rate = %ld\n", i, timeuse, i*1000000/timeuse);
			i = 0;
			timeuse = 0;
		}
	}

	return 0;
}