Ejemplo n.º 1
0
    void _reset(int numBodies, NBodyConfig config)
    {
        randomizeBodies(config, m_hPos, m_hVel, m_hColor, 
            activeParams.m_clusterScale, 
            activeParams.m_velocityScale, 
            numBodies, true);

        setArrays(m_hPos, m_hVel);
    }
Ejemplo n.º 2
0
void reset(BodySystem *system, int numBodies, 
	   NBodyConfig config, bool useGL = true)
{
    // initalize the memory
    randomizeBodies(config, hPos, hVel, hColor, activeParams.m_clusterScale, 
		            activeParams.m_velocityScale, numBodies);

    system->setArray(BodySystem::BODYSYSTEM_POSITION, hPos);
    system->setArray(BodySystem::BODYSYSTEM_VELOCITY, hVel);
    if (useGL)
    {
        renderer->setColors(hColor, nbody->getNumBodies());
        renderer->setSpriteSize(activeParams.m_pointSize);
    }
}
Ejemplo n.º 3
0
 void _reset(int numBodies, NBodyConfig config)
 {
     if (tipsyFile == "")
     {
         randomizeBodies(config, m_hPos, m_hVel, m_hColor,
                         activeParams.m_clusterScale,
                         activeParams.m_velocityScale,
                         numBodies, true);
         setArrays(m_hPos, m_hVel);
     }
     else
     {
         m_nbody->loadTipsyFile(tipsyFile);
         ::numBodies = m_nbody->getNumBodies();
     }
 }
Ejemplo n.º 4
0
//--------------------------------------------------------------
void PartyCLApp::resetSimulation()
{
    ofLogNotice("PartyCLApp::resetSim", "Resetting Nbody system...");

    if (filename.length() == 0) {
        randomizeBodies();
    }
    else {
        damping = 1.0;
        softening = 0.1;
        timestep = 0.016;
        clusterScale = 1.56;
        velocityScale = 2.64;
    }

    system->setArray(NBodySystem::ARRAY_POSITION, (float *)hPos.data());
    system->setArray(NBodySystem::ARRAY_VELOCITY, (float *)hVel.data());

//        renderer->setColors(hColor, numBodies);
}
Ejemplo n.º 5
0
int main(int argc, char *argv[])
{
	unsigned row, col, core;
	e_platform_t platform;
	e_epiphany_t dev;
  	int all_done, core_done;
	int i, x, y;
        int res;
        unsigned int *fp;


       fb = open(FB, O_RDWR);

       if (fb == -1) {
          perror("Unable to open fb " FB);
          return 1;
       }

       // rest here
       res = ioctl(fb, FBIOGET_FSCREENINFO, &fix);
       if (res != 0) {
          perror("getscreeninfo failed");
       	  close(fb);
          return 1;
       }

       //printf("framebuffer size %d @ %08x\n", fix.smem_len, fix.smem_start);

       res = ioctl(fb, FBIOGET_VSCREENINFO, &var);
       if (res != 0) {
          perror("getscreeninfo failed");
          close(fb);
          return 1;
       }

       //printf("size %dx%d @ %d bits per pixel\n", var.xres_virtual, var.yres_virtual, var.bits_per_pixel);

       fp = mmap(NULL, fix.smem_len, O_RDWR, MAP_SHARED, fb, 0);
       if (fp == (void *)-1) {
          perror("mmap failed");
          close(fb);
          return 1;
       }

       //printf("virtual @ %p\n", fp);

       int stride = var.xres_virtual;

	srand(time(NULL));
  	int nBodies = 30000;
	int startFlag = 0x00000001;
  	int iters = 5000;  // simulation iterations
  	const float dt = 0.05f; // time step
  	if (argc > 1) nBodies = atoi(argv[1]);
  	if (argc > 2) iters = atoi(argv[2]);


	Body *buf = (Body *) malloc(sizeof(Body) * nBodies);
	Body *bufOutput = (Body *) malloc(sizeof(Body) * nBodies);

  	randomizeBodies(buf, nBodies); // Init pos / vel data

	e_init(NULL);
	e_reset_system();
	e_get_platform_info(&platform);
	e_open(&dev, 0, 0, 4, 4);
	e_reset_group(&dev);
	e_load_group("e_rob_nbody.srec", &dev, 0, 0, 4, 4, E_FALSE);
    	for (row = 0; row < platform.rows; row++){
      		for (col = 0; col < platform.cols; col++){
			e_write(&dev, row, col, 0x00000004, &nBodies, sizeof(int));
      		}
    	}
	e_write(&dev, 0, 0, 0x1000, (Body *) buf, sizeof(Body) * nBodies);
	x = 0;
//	for(x = 0; x < iters; x++){
	while(1){
		//fprintf(stderr, "Iter %d\n", x);
    		for (row = 0; row < platform.rows; row++){
      			for (col = 0; col < platform.cols; col++){
				e_write(&dev, row, col, 0x00000008, &startFlag, sizeof(int));
      			}
    		}
		e_start_group(&dev);
  		//Check if all cores are done
  		while(1){
    			all_done = 0;
    			for (row = 0; row < platform.rows; row++){
      				for (col = 0; col < platform.cols; col++){
					e_read(&dev, row, col, 0x00000008, &core_done, sizeof(int));
					all_done += core_done;
      				}
    			}
    			if(all_done == 0){
      				break;
    			}
  		}
		e_read(&dev, 0, 0, 0x1000, (Body *) bufOutput, sizeof(Body) * nBodies);
		if(x != 0){
			draw_stars(buf, nBodies, fp, stride, 0x00000000);
		}
		else{
			x = 1;
		}
		draw_stars(bufOutput, nBodies, fp, stride, 0x00ffffff);
		memcpy(buf, bufOutput, sizeof(Body) * nBodies);
	}
	e_close(&dev);

	// Release the allocated buffer and finalize the
	// e-platform connection.
	e_finalize();

	return 0;
}
Ejemplo n.º 6
0
//*****************************************************************************
void InitNbody(cl_device_id dev, cl_context ctx, cl_command_queue cmdq,
               int numBodies, int p, int q, bool bUsePBO, bool bDouble, NBodyConfig config)
{
    // allocate host memory
    hPos = new float[numBodies*4];
    hVel = new float[numBodies*4];
    hF = new float[numBodies*4];
    hForces = new float[numBodies*4];
    hColor = new float[numBodies*4];

    // initalize the memory
    randomizeBodies(&nEdges, config, hPos, hVel, hF, hForces, hColor, activeParams.m_clusterScale,
    		activeParams.m_velocityScale, numBodies);

    float tmpNUM = pow(numBodies, 1./3.);
    float SCALE = 20;
    float tmpINC = SCALE/tmpNUM;
    int n = 0;
    bool bX = true, bY = true, bZ = true; // 1
    bool bZY = true, bZmY = true, bYX = true, bYmX = true, bZX = true, bZmX = true; // 2
    bool bmXYZ = true, bXYZ = true, bXmYZ = true, bmXmYZ = true; // 3

    for (int i = 0; i < numBodies; i++) {
    	for (int j = 0; j < numBodies; j++) {
    		/*
    		 * 1 = 3 kusy
    		 */
    		if ((hPos[j*4] == (hPos[i*4] + tmpINC)) && bX && (hPos[j*4+1] == hPos[i*4+1]) && (hPos[j*4+2] == hPos[i*4+2])) { // x
    			n++;
    			bX = false;
    		}
    		else if ((hPos[j*4+1] == (hPos[i*4+1] + tmpINC)) && bY && (hPos[j*4] == hPos[i*4]) && (hPos[j*4+2] == hPos[i*4+2])) { // y
    			n++;
    			bY = false;
    		}
    		else if ((hPos[j*4+2] == (hPos[i*4+2] + tmpINC)) && bZ && (hPos[j*4+1] == hPos[i*4+1]) && (hPos[j*4] == hPos[i*4])) { // z
    			n++;
    			bZ = false;
    		}

    		/*
    		 * 2 = 6 kusov
    		 */

    		else if (bZY && (hPos[j*4+2] == (hPos[i*4+2] + tmpINC)) && (hPos[j*4+1] == (hPos[i*4+1] + tmpINC)) && (hPos[j*4] == hPos[i*4])) {
    			n++;
    			bZY = false;
    		}
    		else if (bZmY && (hPos[j*4+2] == (hPos[i*4+2] + tmpINC)) && (hPos[j*4+1] == (hPos[i*4+1] - tmpINC)) && (hPos[j*4] == hPos[i*4])) {
    			n++;
    			bZmY = false;
    		}
    		else if (bYX && (hPos[j*4+1] == (hPos[i*4+1] + tmpINC)) && (hPos[j*4] == (hPos[i*4] + tmpINC)) && (hPos[j*4+2] == hPos[i*4+2])) {
    			n++;
    			bYX = false;
    		}
    		else if (bYmX && (hPos[j*4+1] == (hPos[i*4+1] + tmpINC)) && (hPos[j*4] == (hPos[i*4] - tmpINC)) && (hPos[j*4+2] == hPos[i*4+2])) {
    			n++;
    			bYmX = false;
    		}
    		else if (bZX && (hPos[j*4+2] == (hPos[i*4+2] + tmpINC)) && (hPos[j*4] == (hPos[i*4] + tmpINC)) && (hPos[j*4+1] == hPos[i*4+1])) {
    			n++;
    			bZX = false;
    		}
    		else if (bZmX && (hPos[j*4+2] == (hPos[i*4+2] + tmpINC)) && (hPos[j*4] == (hPos[i*4] - tmpINC)) && (hPos[j*4+1] == hPos[i*4+1])) {
    			n++;
    			bZmX = false;
    		}
    		/*
    		 * 3 = 4 kusy
    		 */
    		else if (bmXYZ && (hPos[j*4] == (hPos[i*4] - tmpINC)) && (hPos[j*4+1] == (hPos[i*4+1] + tmpINC)) && (hPos[j*4+2] == (hPos[i*4+2] + tmpINC))) {
    			n++;
    			bmXYZ = false;
    		}
    		else if (bXYZ && (hPos[j*4] == (hPos[i*4] + tmpINC)) && (hPos[j*4+1] == (hPos[i*4+1] + tmpINC)) && (hPos[j*4+2] == (hPos[i*4+2] + tmpINC))) {
    			n++;
    			bXYZ = false;
    		}
    		else if (bXmYZ && (hPos[j*4] == (hPos[i*4] + tmpINC)) && (hPos[j*4+1] == (hPos[i*4+1] - tmpINC)) && (hPos[j*4+2] == (hPos[i*4+2] + tmpINC))) {
    			n++;
    			bXmYZ = false;
    		}
    		else if (bmXmYZ && (hPos[j*4] == (hPos[i*4] - tmpINC)) && (hPos[j*4+1] == (hPos[i*4+1] - tmpINC)) && (hPos[j*4+2] == (hPos[i*4+2] + tmpINC))) {
    			n++;
    			bmXmYZ = false;
    		}
    	}
    	//shrLog("\n");
    	bX = true;
    	bY = true;
    	bZ = true;
    	bZY = true, bZmY = true, bYX = true, bYmX = true, bZX = true, bZmX = true;
    	bmXYZ = true, bXYZ = true, bXmYZ = true, bmXmYZ = true;
    }

    nEdges = n;

    hEdge = new float[nEdges*4];

    // New nbody system for Device/GPU computations
    nbodyGPU = new BodySystemOpenCL(numBodies, nEdges, dev, ctx, cmdq, p, q, bUsePBO, bDouble);
    nbody = nbodyGPU;

    // Set sim parameters
    nbody->setSoftening(activeParams.m_softening);
    nbody->setDamping(activeParams.m_damping);
}