Example #1
0
//\begin{>>PPP_2d_Jacobi_1d_Part.tex}{\subsubsection{writeToFile}}
void PPP_2d_Jacobi_1d_Part::
writeToFile(ostream &outFile )
//================================================================
// /Description:  Writes the Timing data to a file named from
//   the benchmark name.
//
// /outFile (input):  The stream to write data to.
//
// /Return Values: None.
//
// /Errors:
//   None.
//
// /Author:  BJM
// /Date:  29 August 2000
//\end{PPP_2d_Jacobi_1d_Part.tex}
//================================================================
{
  int theNumProcs = 1;
  int myProcNum   = 0;

// MPI_Comm_rank(MPI_COMM_WORLD, &myProcNum);
// MPI_Comm_size(MPI_COMM_WORLD, &theNumProcs);
  
  computeStatistics();

  if(myProcNum == 0 )
  {
// Parallel specific data commented out  
// outFile<<setw(13)<<theNumProcs<<setw(13)<<mUnknownsPerProc; 
   outFile<<setw(13)<<mUnknownsPerProc;
   BenchmarkBase::writeToFile( outFile );
  }
}
Example #2
0
void ValueProfile::computeStatistics(Statistics& statistics) const
{
    for (unsigned i = 0; i < numberOfBuckets; ++i) {
        JSValue value = JSValue::decode(m_buckets[i]);
        if (!value)
            continue;
        
        statistics.samples++;
        
        if (value.isInt32())
            statistics.int32s++;
        else if (value.isDouble())
            statistics.doubles++;
        else if (value.isCell())
            computeStatistics(value.asCell()->structure()->classInfo(), statistics);
        else if (value.isBoolean())
            statistics.booleans++;
    }
}
Example #3
0
void updateInfoLine()
{
	char info[100];
	computeStatistics();
	/*
	if (errorPerLetter > 0.99)
	{
		sprintf(info, "L/min = %3.0f | Mistakes/100L = XX", letterPerMin);
	}
	else
	{
		sprintf(info, "L/min = %3.0f | Mistakes/100L = %2.0f%%", letterPerMin, errorPerLetter*100);
	}
	 */
	sprintf(info, "L/min = %3.0f | Mistakes %s %2.0f%%%%",
					letterPerMin,
					(errorPerLetter > 0.99) ? ">" : "=",
					((errorPerLetter > 0.99) ? 0.99 : errorPerLetter)*100);
	//sprintf(info, "tL = %3d | tE = %3d | tT = %4.2f | L/T = %.4f | E/L = %2.0f",
	//				totalLetter, totalError, totalTime, letterPerMin, errorPerLetter*100);
	attron(COLOR_PAIR(COLOR_ID_DEFAULT));
	mvprintw(infoLineY, infoLineX1, info);
}
int main(int argc, char**argv)
{
	capture.open(0);
	if (capture.isOpened() == false)
	{
		std::cerr << "no capture device found" << std::endl;
		return 1;
	}
	capture.set(CV_CAP_PROP_FRAME_WIDTH,  vgaSize.width);
	capture.set(CV_CAP_PROP_FRAME_HEIGHT, vgaSize.height);
	if (capture.get(cv::CAP_PROP_FRAME_WIDTH) != (double)vgaSize.width || capture.get(cv::CAP_PROP_FRAME_HEIGHT) != (double)vgaSize.height)
	{
		std::cerr << "current device doesn't support " << vgaSize.width << "x" << vgaSize.height << " size" << std::endl;
		return 2;
	}
	cv::Mat image;
	capture >> image;

	cv::namedWindow(windowName);
	cv::imshow(windowName, image);

	initCuda();
	initArray(image);

	char key = -1;
	enum device statusDevice = useCpuSimd;
	enum precision statusPrecision = precisionFloat;
	int index = 1;
	cv::Mat stub = cv::imread(imagePath[index][0], cv::IMREAD_UNCHANGED);
	cv::Mat gain = cv::Mat(stub.rows, stub.cols/2, CV_16SC1, stub.data);
	double elapsedTime;
	while (isFinish(key) == false)
	{
		capture >> image;

		switch (key)
		{
		case 'h':
		case 'H':
			// switch to half precision
			statusPrecision = precisionHalf;
			std::cout << std::endl << header << "half  " << std::endl;
			stub = cv::imread(imagePath[index][0], cv::IMREAD_UNCHANGED);
			gain = cv::Mat(stub.rows, stub.cols/2, CV_16SC1, stub.data);
			break;
		case 'f':
		case 'F':
			// switch to single precision
			statusPrecision = precisionFloat;
			std::cout << std::endl << header << "single" << std::endl;
			stub = cv::imread(imagePath[index][1], cv::IMREAD_UNCHANGED);
			gain = cv::Mat(stub.rows, stub.cols, CV_32FC1, stub.data);
			break;
		case 'b':
		case 'B':
			// switch to gray gain
			statusPrecision = precisionByte;
			std::cout << std::endl << header << "char" << std::endl;
			gain = cv::imread(imagePath[index][2], cv::IMREAD_GRAYSCALE);
			break;
		case '0':
		case '1':
			index = key - '0';
			switch (statusPrecision)
			{
			case precisionHalf:
				// precision half
				stub = cv::imread(imagePath[index][0], cv::IMREAD_UNCHANGED);
				gain = cv::Mat(stub.rows, stub.cols/2, CV_16SC1, stub.data);
				break;
			case precisionFloat:
				// precision single
				stub = cv::imread(imagePath[index][1], cv::IMREAD_UNCHANGED);
				gain = cv::Mat(stub.rows, stub.cols, CV_32FC1, stub.data);
				break;
			case precisionByte:
				// precision single
				gain = cv::imread(imagePath[index][2], cv::IMREAD_GRAYSCALE);
				break;
			default:
				break;
			}
			break;
		case 'c':
		case 'C':
			std::cout << std::endl << "Using CPU SIMD           " << std::endl;
			statusDevice = useCpuSimd;
			break;
		case 'g':
		case 'G':
			std::cout << std::endl << "Using GPU                " << std::endl;
			statusDevice = useGpu;
			break;
		default:
			break;
		}

		if (statusDevice == useCpuSimd)
		{
			elapsedTime = multiplyImage(image, gain);
		}
		else
		{
#ifdef HAVE_CUDA
			// CUDA
			elapsedTime = multiplyImageCuda(image, gain);
#endif // HAVE_CUDA
		}
		computeStatistics(elapsedTime, key);

		if (key == 's' || key == 'S')
		{
			cv::imwrite(dumpFilename, image);
		}

		cv::imshow(windowName, image);
		key = cv::waitKey(1);
	}
	std::cout << std::endl;
	cv::destroyAllWindows();
	releaseArray();

	return 0;
}
//---------------------------------------------------------------------------------
void particleManager::update() {
    //if we are meant to be in formation


    if (ofGetFrameNum() % 4 == 0) {
        computeStatistics();
    }


    if (mode == 2) {
        if (ofRandom(0, 1) > 0.91f) {
            int pos = (int)(ofRandom(0, 0.99) * particles.size());
            particles[pos].peakMe(1);

            ofxOscMessage msg;
            msg.setAddress("/bang");								//	bang
            msg.addStringArg("explosion");					//	handTrigger
            msg.addIntArg(4);									//	SCENE 4 (?)

            float x = ofClamp(particles[pos].pos.x / OFFSCREEN_WIDTH, 0, 1);
            float y = ofClamp(particles[pos].pos.y / OFFSCREEN_HEIGHT, 0, 1);

            msg.addFloatArg(x);								// centroid x
            msg.addFloatArg(y);								// centroid y


            //DAITO --- >   /bang /explosion /4 /x(noramlized) /y(noramlized)

            ofxDaito::sendCustom(msg);


        }
    }

    if (mode == 3) {
        if (ofRandom(0, 1) > 0.85f) {
            int pos = (int)(ofRandom(0, 0.99) * particles.size());

            float angle = ofRandom(0, TWO_PI);
            particles[pos].directionallyPeakMe(1, angle);

            ofxOscMessage msg;
            msg.setAddress("/bang");									//	bang
            msg.addStringArg("explosionDirectional");					//	handTrigger
            msg.addIntArg(4);											//	SCENE 4 (?)

            float x = ofClamp(particles[pos].pos.x / OFFSCREEN_WIDTH, 0, 1);
            float y = ofClamp(particles[pos].pos.y / OFFSCREEN_HEIGHT, 0, 1);

            msg.addFloatArg(x);											// centroid x
            msg.addFloatArg(y);											// centroid y
            msg.addFloatArg(angle / TWO_PI);								// angle of explosion (0-1)


            //DAITO --- >   /bang /explosionDirectional /4 /x(noramlized) /y(noramlized) /angle

            ofxDaito::sendCustom(msg);



        }
    }

    if (mode == 4) {
        if (ofRandom(0, 1) > 0.82f) {
            int pos = (int)(ofRandom(0, 0.99) * particles.size());
            float angle = ofRandom(0, TWO_PI);
            particles[pos].directionallyPeakMe(1, angle);
            ofxOscMessage msg;
            msg.setAddress("/bang");									//	bang
            msg.addStringArg("explosionDirectional");					//	handTrigger
            msg.addIntArg(4);											//	SCENE 4 (?)

            float x = ofClamp(particles[pos].pos.x / OFFSCREEN_WIDTH, 0, 1);
            float y = ofClamp(particles[pos].pos.y / OFFSCREEN_HEIGHT, 0, 1);

            msg.addFloatArg(x);											// centroid x
            msg.addFloatArg(y);											// centroid y
            msg.addFloatArg(angle / TWO_PI);								// angle of explosion (0-1)


            //DAITO --- >   /bang /explosionDirectional /4 /x(noramlized) /y(noramlized) /angle

            ofxDaito::sendCustom(msg);
        }

        if (ofRandom(0, 1) > 0.91f) {
            int pos = (int)(ofRandom(0, 0.99) * particles.size());
            particles[pos].peakMe(1);
            ofxOscMessage msg;
            msg.setAddress("/bang");								//	bang
            msg.addStringArg("explosion");					//	handTrigger
            msg.addIntArg(4);									//	SCENE 4 (?)

            float x = ofClamp(particles[pos].pos.x / OFFSCREEN_WIDTH, 0, 1);
            float y = ofClamp(particles[pos].pos.y / OFFSCREEN_HEIGHT, 0, 1);

            msg.addFloatArg(x);								// centroid x
            msg.addFloatArg(y);								// centroid y


            //DAITO --- >   /bang /explosion /4 /x(noramlized) /y(noramlized)

            ofxDaito::sendCustom(msg);
        }
    }


    if (mode != 5) {
        for (int j = 0; j < particles.size(); j ++) {
            particles[j].radius = 2 + 20 * particles[j].energy;
            particles[j].fiveEnergy *= 0.50;
        }


    } else {
        for (int j = 0; j < particles.size(); j ++) {
            particles[j].radius = 1;

            particles[j].fiveEnergy = 0.94f * particles[j].fiveEnergy + 0.06f * 1.0;
        }
    }


    if (VFs.size() == 0) {
        if (ofRandom(0, 1) > 0.16) {
            vfAdder VA;
            VFs.push_back(VA);
            VFs[VFs.size()-1].setup();
        }
    } else {

        bool bErase = false;
        if (ofGetElapsedTimef() - VFs[0].startTime > VFs[0].timeOn) {
            bErase = true;
        }
        if (bErase == true) {
            VFs.erase(VFs.begin());
        }
    }

    if (VFs.size() > 0 && ofGetFrameNum() % 4 == 0) {


        ofxOscMessage msg;
        msg.setAddress("/continuous");									//	bang
        msg.addStringArg("particlePusher");					//	handTrigger
        msg.addIntArg(4);											//	SCENE 4 (?)

        float x = ofClamp(VFs[0].point.x / OFFSCREEN_WIDTH, 0, 1);
        float y = ofClamp(VFs[0].point.y / OFFSCREEN_HEIGHT, 0, 1);

        msg.addFloatArg(x);											// centroid x
        msg.addFloatArg(y);											// centroid y

        //DAITO --- >   /continuous /particlePusher /4 /x(noramlized) /y(noramlized)

        ofxDaito::sendCustom(msg);
    }



    VF.fade(0.99f);

    for (int i = 0; i < particles.size(); i++) {

        ofxVec2f velFromVF = VF.readFromField(particles[i].pos.x / (float)OFFSCREEN_WIDTH, particles[i].pos.y / (float)OFFSCREEN_HEIGHT);

        particles[i].resetForce();
        particles[i].bitFlagW = 0;
        particles[i].bitFlagH = 0;
        computeBinPosition((int)(particles[i].pos.x), (int)(particles[i].pos.y), &particles[i].bitFlagW, &particles[i].bitFlagH);

        if (!particles[i].bBeenChosen) {
            particles[i].vel.x += velFromVF.x * 3;
            particles[i].vel.y += velFromVF.y * 3;
        }

        /*
        // get the pos from the particle system
        if(i < NUM_PARTICLES_VBO) {
        	vboPts[i][0] = particles[i].pos.x;
        	vboPts[i][1] = particles[i].pos.y;
        	vboPts[i][2] = particles[i].pos.z;

        	vboPtsSize[i] = MIN(particles[i].radius/5.0, 1.0) * maxPtsSize;


        	vboColor[i][0] = 1.0;
        	vboColor[i][1] = MIN(particles[i].radius/5.0, 1.0);
        	vboColor[i][2] = 1.0;
        	vboColor[i][3] = MIN(particles[i].radius/5.0, maxAlpha);


        }*/
    }



    //---------------------------- delauny based forces??
    Delaunay::Point tempP;
    if ( v.size() == 0) {
        for (int i = 0; i < particles.size(); i++) {
            tempP[0] = particles[i].pos.x;
            tempP[1] = particles[i].pos.y;
            v.push_back(tempP);
        }
    } else {
        for (int i = 0; i < particles.size(); i++) {
            v[i][0] = particles[i].pos.x;
            v[i][1] = particles[i].pos.y;
        }
    }
    Delaunay delobject(v);
    delobject.Triangulate();


    //------------------------------------------ peak
    if (ofGetFrameNum() % 5 == 0)
        for (Delaunay::fIterator fit  = delobject.fbegin();
                fit != delobject.fend();
                ++fit) {
            for (int i = 0; i < 3; ++i) {

                int pta = delobject.Org(fit);
                int ptb = delobject.Sym(fit, i);
                if (ptb != -1) {
                    if (particles[pta].bBeenPeaked) {
                        particles[ptb].peakMe(particles[pta].energy * 0.86f);
                        if (i == 2) particles[pta].bBeenPeaked = false;
                    }
                }
            }
        }


    if (ofGetFrameNum() % 2 == 0)
        for (Delaunay::fIterator fit  = delobject.fbegin();
                fit != delobject.fend();
                ++fit) {

            int pta = delobject.Org(fit);

            if (particles[pta].bBeenDirectionallyPeaked) {

                float angle = particles[pta].direction;

                int minIndex = -1;
                float minAngle = 10000;
                for (int i = 0; i < 3; ++i) {

                    int ptb = delobject.Sym(fit, i);
                    if (ptb != -1) {

                        float angleB = atan2( particles[ptb].pos.y -  particles[pta].pos.y, particles[ptb].pos.x -  particles[pta].pos.x);
                        float diffAngle = angle - angleB;
                        if (diffAngle < -PI) diffAngle += TWO_PI;
                        if (diffAngle > PI) diffAngle -= TWO_PI;
                        if (fabs(diffAngle) < minAngle) {
                            minAngle = fabs(diffAngle);
                            minIndex = delobject.Sym(fit, i);;
                        }

                    }
                }

                particles[pta].bBeenDirectionallyPeaked = false;

                if (minIndex != -1) {
                    particles[minIndex].directionallyPeakMe(particles[pta].energy*0.96, angle);
                }


            }
        }






    for (Delaunay::fIterator fit  = delobject.fbegin();
            fit != delobject.fend();
            ++fit) {
        for (int i = 0; i < 3; ++i) {

            int pta = delobject.Org(fit);
            int ptb = delobject.Sym(fit, i);
            if (ptb != -1) {
                if (!(particles[pta].bBeenChosen && particles[ptb].bBeenChosen)) {

                    bool bAnyArrow = particles[ptb].bBeenChosen || particles[ptb].bBeenChosen;

                    float radius = particles[pta].radius + particles[ptb].radius;

                    if (mode != 5) radius *= 2.5;


                    float distance = (particles[pta].pos - particles[ptb].pos).length();

                    if (!bAnyArrow) {
                        if ( distance < radius) {
                            if (mode != 5) particles[pta].addRepulsionForce(particles[ptb], radius, 0.1f);
                            else particles[pta].addRepulsionForce(particles[ptb], radius, 0.026f);
                        }
                        if ( distance < 100)  particles[pta].addAttractionForce(particles[ptb], 100, 0.001f);
                    } else {
                        if ( distance < 33) particles[pta].addRepulsionForce(particles[ptb], 33, 0.2f);
                    }


                }
            }
        }
    }
    for (int i = 0; i < particles.size(); i++) {

        if (mode == 4) {
            if (!particles[i].bBeenChosen) particles[i].addAttractionForce(
                    OFFSCREEN_WIDTH / 2, OFFSCREEN_HEIGHT / 2 + OFFSCREEN_HEIGHT / 4, 6000, 0.008);
        } else {
            if (mode != 5) {
                if (!particles[i].bBeenChosen) particles[i].addAttractionForce(
                        OFFSCREEN_WIDTH / 2, OFFSCREEN_HEIGHT / 2 + OFFSCREEN_HEIGHT / 4, 6000, 0.003);
            } else {
                particles[i].addAttractionForce( particles[i].lockTarget.x, particles[i].lockTarget.y, 6000, 0.06); //0.2f -0.2*sin(ofGetElapsedTimef()));
                //cout << particles[i].lockTarget.x <<  " " <<  particles[i].lockTarget.y << endl;

            }
        }

    }



    // some perlin forces:


    if (mode == 1) {
        for (int i = 0; i < particles.size(); i++) {
            if (!particles[i].bBeenChosen) {

                float xyRads = getRads(particles[i].pos.x / 3.0f, particles[i].pos.y / 3.0f, ofGetElapsedTimef() / 100, 10.f, 15.f);
                //float yRads = getRads(xLoc, yLoc, 10.f, 15.f);

                particles[i].addForce( cos(xyRads) * .05, -sin(xyRads) * .05);
            }
        }
    }

    for (int i = 0; i < particles.size(); i++) {


        /*for(int j = 0; j < i; j++){
        if (particles[i].bInSameBin(particles[j])){

        if (particles[i].bBeenChosen && particles[j].bBeenChosen) continue;

        if (particles[i].bBeenChosen || particles[j].bBeenChosen)  particles[i].addRepulsionForce(particles[j], 60, 0.8f);
        else particles[i].addRepulsionForce(particles[j], 20, 0.2f);
        particles[i].addAttractionForce(particles[j], 100, 0.0001f);
        }
        }*/
        particles[i].addDampingForce();
        particles[i].update();
        particles[i].update();
        if (ofGetFrameRate() < 22) particles[i].update();

    }

    for (int i = 0; i < particles.size(); i++) {

    }

    for (int i = 0; i < VFs.size(); i++) {
        VFs[i].update();
    }


    for (int i = 0; i < VFs.size(); i++) {

        if (mode != 5) {
            VF.addIntoField( (VFs[i].point.x) / (float)OFFSCREEN_WIDTH, VFs[i].point.y / (float)OFFSCREEN_HEIGHT, VFs[i].diffPoint*0.001  , 0.093 * 1.6);
        }
    }

}
Example #6
0
/*-----------------------------------------------------------------------------
 * cntProcessPacket()
 *---------------------------------------------------------------------------*/
struct connection *	cntProcessPacket( struct packet *p )
{
    int    i;
    int    connectionIdx;
    uchar  bFound;

    assert( p != NULL );

    /* comprobamos si es un paquete de una conexión que ya procesamos */
    bFound = FALSE;
    for( i = 0; i < MAX_CONNECTIONS  &&  bFound == FALSE; i++ )
    {
        /* comprobamos que el par origen-destino coincide */
        if( belongToConnection( &(connections[i].c), p ) == TRUE )
        {
            connectionIdx = i;
            bFound        = TRUE;
        }
    }

    /* si ya existe, lo contabilizamos en las estadísticas */
    if( bFound == TRUE )
    {
        /* calculamos estadísticas */
        computeStatistics( &connections[connectionIdx], p );

        /* devolvemos la conexción asociada */
        return  &(connections[connectionIdx].c);
    }
    /* si no pertenece a ninguno */
    else
    {
        /* buscamos el primer slot libre */
        for( i = 0; i < MAX_CONNECTIONS && bFound == FALSE; i++ )
        {
            if( connections[i].free == TRUE )
            {
                connectionIdx = i;
                bFound        = TRUE;
            }
        }

        if( bFound == TRUE )
        {
            /* creamos una nueva conexión */
            if( buildConnection( &connections[connectionIdx], p ) == TRUE )
            {
                /* contabilizamos las primeras estadísticas */
                computeStatistics( &connections[connectionIdx], p );

                /* devolvemos la conexción asociada */
                return  &(connections[connectionIdx].c);
            }
            else
            {
                return  NULL;
            }
        }
        else
        {
            /* no tenemos espacio libre para procesar más conexiones */
            return  NULL;
        }
    }
}