Exemple #1
0
main()
{
 int screenInput=CONSOLE_INPUT;
 int numberOfTasks=0;
 int count=0;
 float density=0;
 float utilization=0;
 int hyperperiod=0;
 FILE* fp;

 if(screenInput)
 {
	 printf("Enter Number of Tasks: ");
	 scanf("%d",&numberOfTasks);
	 while (count < numberOfTasks)
	 {
		 	 printf("Enter Release Time of Task %d: ", count);
		 	 scanf("%d",&taskInfo[count][0]);
		 	 printf("Enter Period of Task %d: ", count);
		 	 scanf("%d",&taskInfo[count][1]);
		 	 printf("Enter Execution Time of Task %d: ", count);
		 	 scanf("%d",&taskInfo[count][2]);
		 	 printf("Enter Deadline of Task %d: ", count);
		 	 scanf("%d",&taskInfo[count][3]);
	 		 count++;
	 }
 }
 else
 {
	 fp=fileOpen();
	 numberOfTasks=fReadNumOfTasks(fp);
	 printf("Number of Tasks: %d\n",numberOfTasks);
	 fReadTaskDetails(fp, numberOfTasks);
	 while (count < numberOfTasks)
	 {
		 printf("%d %d %d %d\n",taskInfo[count][0], taskInfo[count][1], taskInfo[count][2], taskInfo[count][3]);
		 count++;
	 }
	 fileClose(fp);
 }
 density=calculateDensity(numberOfTasks);
 printf("Density: %f\n",density);
 utilization=calculateCpuUtilization(numberOfTasks);
 printf("Utilization: %f\n",utilization);
 if (density > 1)
 {
	 printf("Density for the task set is more than 1. Schedule cannot be created.");
 }
 else
 {
	 hyperperiod=calculateHyperPeriod(numberOfTasks);
	 printf("Hyperperiod: %d\n",hyperperiod);
	 calculateLLF(numberOfTasks, hyperperiod);
 }
}
Exemple #2
0
std::string SingleParticle2dx::DataStructures::Particle::getDataString()
{
	std::string result = SingleParticle2dx::Utilities::StringFunctions::TtoString(getParticleNumber());
	result += "\t" + getGlobalParticleInformation().getDataString();
	result += "\t" + SingleParticle2dx::Utilities::StringFunctions::TtoString(getUseForReconstruction());
	result += "\t" + SingleParticle2dx::Utilities::StringFunctions::TtoString(getLastAngularChange());
	result += "\t" + getParticleShift().getDataString();
	result += "\t" + getInitialOrientation().getDataString();
	result += "\t" + getOldOrientation().getDataString();
	result += "\t" + getNewOrientation().getDataString();
	result += "\t" + SingleParticle2dx::Utilities::StringFunctions::TtoString(getSimMeasure());
	result += "\t" + SingleParticle2dx::Utilities::StringFunctions::TtoString(getQuality());
	result += "\t" + SingleParticle2dx::Utilities::StringFunctions::TtoString(getConsistency());
	result += "\t" + SingleParticle2dx::Utilities::StringFunctions::TtoString(getWeight());
	result += "\t" + SingleParticle2dx::Utilities::StringFunctions::TtoString(getContainerNumber());
	result += "\t" + SingleParticle2dx::Utilities::StringFunctions::TtoString(getIsCMParticle());
	result += "\t" + SingleParticle2dx::Utilities::StringFunctions::TtoString(calculateDensity());
	result += "\t" + getClassInformation().getDataString();
	
	return result;
}
void FluidSystem::update(float deltaTime) //整个particle或流体的update
{
    assert(m_bInitialized);

    float *dPos;
    if (m_bUseOpenGL)
    {
		m_dPos = (float *)mapGLBufferObject(&m_cuda_posvbo_resource);
		m_dVel = (float *)mapGLBufferObject(&m_cuda_velvbo_resource);

    }
    else
    {
		m_dPos = (float *)m_cudaPosVBO;
		m_dVel = (float *)m_cudaVelVBO;
    }
/////////////////////////////////////////////////////calculate time
	cudaEvent_t start, stop;
	cudaEventCreate(&start);
	cudaEventCreate(&stop);
	// Start record
	cudaEventRecord(start, 0);
///////////////////////////////////////////////////////////////////////

    setParameters(&m_params);

    integrateSystem(
		m_dPos,
        m_dVel,
		m_dDen,
		m_dPre,
        deltaTime,
        m_numParticles,
		buoyancyForce);

	//calculateBuoyancy();

	cudaEvent_t start1, stop1;
	cudaEventCreate(&start1);
	cudaEventCreate(&stop1);
	// Start record
	cudaEventRecord(start1, 0);

    calcHash(
        m_dGridParticleHash,
        m_dGridParticleIndex,
		m_dPos,
        m_numParticles);

    sortParticles(m_dGridParticleHash, m_dGridParticleIndex, m_numParticles);

    reorderDataAndFindCellStart(
        m_dCellStart,
        m_dCellEnd,
        m_dSortedPos,
        m_dSortedVel,
        m_dGridParticleHash,
        m_dGridParticleIndex,
		m_dPos,
        m_dVel,
        m_numParticles,
        m_numGridCells,
		m_dSortedDen,
		m_dSortedPre,
		m_dDen,   //old density
		m_dPre,//old pressure
		m_dSortedColorf,
		m_dColorf);

	cudaEventRecord(stop1, 0);
	cudaEventSynchronize(stop1);
	float elapsedTime1;
	cudaEventElapsedTime(&elapsedTime1, start1, stop1); // that's our time!

	std::cout <<"neighbour " <<elapsedTime1 << endl;

	// Clean up:
	cudaEventDestroy(start1);
	cudaEventDestroy(stop1);

	/*colorfield(
		m_dSortedPos,
		m_dGridParticleIndex,
		m_dCellStart,
		m_dCellEnd,
		m_numParticles,
		m_numGridCells,
		m_dColorf,
		m_dSortedColorf);*/
	//
	copyArrayFromDevice(m_hDen, m_dDen, 0, sizeof(float) * m_numParticles);


	/*glBindBufferARB(GL_ARRAY_BUFFER, m_colorVBO);
	float *data = (float *)glMapBufferARB(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
	float *ptr = data;

	for (uint i = 0; i<m_numParticles; i++)
	{
		float t = i / (float)m_numParticles;
		if (  m_hDen[i]<2.5f){
			colorRamp(1, 1, 1, ptr);
			ptr += 3;
			*ptr++ = 0.1f;
		}
		else
		{
			colorRamp(0, 1, 1, ptr);
			ptr += 3;
			*ptr++ = 0.1f;
		}

	}

	glUnmapBufferARB(GL_ARRAY_BUFFER);*/


	cudaEvent_t start2, stop2;
	cudaEventCreate(&start2);
	cudaEventCreate(&stop2);
	// Start record
	cudaEventRecord(start2, 0);

	calculateDensity(m_dSortedPos,
		m_dGridParticleIndex,
		m_dCellStart,
		m_dCellEnd,
		m_numParticles,
		m_dDen);

    collide(
        m_dVel, //new velocity
        m_dSortedPos,
        m_dSortedVel,
        m_dGridParticleIndex,
        m_dCellStart,
        m_dCellEnd,
        m_numParticles,
        m_numGridCells,
		m_dDen, //new density
		m_dPre, //new pressure
		m_dSortedDen,
		m_dSortedPre,
		m_dPos,
		buoyancyForce);

	cudaEventRecord(stop2, 0);
	cudaEventSynchronize(stop2);
	float elapsedTime2;
	cudaEventElapsedTime(&elapsedTime2, start2, stop2); // that's our time!

	std::cout << "renew " << elapsedTime2 << endl;

	// Clean up:
	cudaEventDestroy(start2);
	cudaEventDestroy(stop2);
	////////////////////////////////////////////////////////////stop calculate time
	cudaEventRecord(stop, 0);
	cudaEventSynchronize(stop);
	float elapsedTime;
	cudaEventElapsedTime(&elapsedTime, start, stop); // that's our time!

	std::cout << "whole " << elapsedTime << endl;

	// Clean up:
	cudaEventDestroy(start);
	cudaEventDestroy(stop);
	//////////////////////////////////////////////////////////

    if (m_bUseOpenGL)
    {
        unmapGLBufferObject(m_cuda_posvbo_resource);
		unmapGLBufferObject(m_cuda_velvbo_resource);
    }
}
Exemple #4
0
/** Find density-attractor for an entity. The density-attractor is
 * obtained executing a hill climbing algorithm.
 *
 *  @param entity The spatial point used to calculate the gradient.
 *  @param iter Iterator over all dataset entities.
 *  @param sigma Parameter that ponderates the influence of an entity into
 *  another
 *
 * @return An entity that is the density-attractor for the given
 *  entity.
 * */
const DatasetEntity DenclueFunctions::getDensityAttractor( const DatasetEntity& entity, const HyperSpace& spatial_region, HyperSpace::EntityIterator iter, double sigma ){


    const double delta = 1;

    HyperSpace::EntityIterator initial_iter = iter;

    //DatasetEntity last_attractor(entity); // Set the initial density-attractor to the received entity
    DatasetEntity curr_attractor(entity);
    DatasetEntity *found_attractor = NULL;


    // Execute the hill climbing algorithm until it finds the local maxima of density function
    unsigned MAX_ITERATIONS = 1000;
    bool reachedTop = false;
    do{

        // Avoid infinite loops
        if( --MAX_ITERATIONS <= 0 )  break;


        // Store last calculated values for further comparison
        DatasetEntity last_attractor(curr_attractor);


        // Calculate the gradient of density function at current candidate to attractor
        HyperSpace::EntityIterator gradient_iter = initial_iter;
        vector<double> curr_gradient =
            DenclueFunctions::calculateGradient(last_attractor, initial_iter,
                    sigma);


        // Build an entity to represent the gradient
        ostringstream grad_entity_str;
        for(unsigned i=0 ; i < curr_gradient.size() ; i++){

            if( i != 0 ) grad_entity_str << Constants::CSV_SEPARATOR;
            grad_entity_str << curr_gradient[i];

        }
        grad_entity_str << Constants::EOL;

        DatasetEntity grad_entity(entity.getNumOfDimensions());
        grad_entity.buildEntityFromString(grad_entity_str.str());


        // Calculate next candidate to attractor
        long double grad_entity_norm = grad_entity.getEuclideanNorm();


        assert( grad_entity_norm > 0 );

        curr_attractor = last_attractor + ( ( (long double)(delta/grad_entity_norm)) * grad_entity );


        // Calculate density in current attractor
        HyperSpace::EntityIterator density_iter = initial_iter;
        density_iter.begin();
        double curr_density = calculateDensity( curr_attractor, density_iter, sigma );

        curr_attractor.setDensity(curr_density);

        // Verify whether local maxima was found
        reachedTop = ( curr_attractor.getDensity() < last_attractor.getDensity() );
        if( reachedTop ) found_attractor = new DatasetEntity(last_attractor);


    }while( !reachedTop );

    if( MAX_ITERATIONS <= 0 )  found_attractor = new DatasetEntity(curr_attractor);


    return *found_attractor;
}