Exemple #1
0
	QuantumStateITPP(unsigned int dimension, std::string state_type="Random"){
		coefficients.set_size(dimension);
		if (state_type=="Random"){
			InitializeRandom( ) ;
		}
		else if (state_type=="Separable"){
			InitializeQubitSeparable( );	
		}
		else if (state_type=="BellRandom"){
			BellRandom( );	
		}
		else if (state_type=="Bell"){
			coefficients=0.;
			coefficients(0)=1;
			coefficients(dimension-1)=1;
			normalize();
		} else {
			std::cerr  << "Illegal type initializing a QuantumState";
			exit(1);
		}
	}
Exemple #2
0
void Initialize( int& argc, char**& argv )
{
    if( ::numElemInits > 0 )
    {
        ++::numElemInits;
        return;
    }

    ::args = new Args( argc, argv );

    ::numElemInits = 1;
    if( !mpi::Initialized() )
    {
        if( mpi::Finalized() )
        {
            LogicError
            ("Cannot initialize elemental after finalizing MPI");
        }
#ifdef EL_HYBRID
        const Int provided =
            mpi::InitializeThread
            ( argc, argv, mpi::THREAD_MULTIPLE );
        const int commRank = mpi::Rank( mpi::COMM_WORLD );
        if( provided != mpi::THREAD_MULTIPLE && commRank == 0 )
        {
            cerr << "WARNING: Could not achieve THREAD_MULTIPLE support."
                 << endl;
        }
#else
        mpi::Initialize( argc, argv );
#endif
        ::elemInitializedMpi = true;
    }
    else
    {
#ifdef EL_HYBRID
        const Int provided = mpi::QueryThread();
        if( provided != mpi::THREAD_MULTIPLE )
        {
            throw std::runtime_error
            ("MPI initialized with inadequate thread support for Elemental");
        }
#endif
    }

#ifdef EL_HAVE_QT5
    InitializeQt5( argc, argv );
#endif

    // Queue a default algorithmic blocksize
    EmptyBlocksizeStack();
    PushBlocksizeStack( 128 );

    // Build the default grid
    Grid::InitializeDefault();

#ifdef EL_HAVE_QD
    InitializeQD();
#endif

    InitializeRandom();

    // Create the types and ops
    // NOTE: mpfr::SetPrecision created the BigFloat types
    mpi::CreateCustom();
}
Exemple #3
0
int main()
{
	RCC_ClocksTypeDef RCC_Clocks;
	RCC_GetClocksFreq(&RCC_Clocks);

	SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);

	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

	InitializeLEDs();
	InitializeUserInterface();
	InitializeRandom();
	InitializeRumble();

	//Clear framebuffers
	memset(ADDR_FRAMEBUFFER1, 0x00, 320*200);
	memset(ADDR_FRAMEBUFFER2, 0x00, 320*200);

	//Create drawing surfaces
	InitializeBitmap(&frame1,320,200,320,ADDR_FRAMEBUFFER1);
	InitializeBitmap(&frame2,320,200,320,ADDR_FRAMEBUFFER2);

	//Switch on VGA
	IntializeVGAScreenMode320x200(ADDR_FRAMEBUFFER1);

	if(!TheGame) {
		EnableDebugOutput(DEBUG_USART);
		fprintf(stderr, "PANIC: Game structure pointer is NULL\r\n");
		return -1;
	}

	if(TheGame->currentState)
		TheGame->currentState->Init(NULL);

	if(!TheGame->currentState->Update || !TheGame->currentState->Draw) {
		fprintf(stderr, "PANIC: Update and/or Draw function pointer is NULL\r\n");
		return -1;
	}

	Gamestate *currentState = TheGame->currentState;

	while(1)
	{
		oldTime = currentTime;
		currentTime = SysTickCounter;
		if (currentState != TheGame->currentState)
		{
			Gamestate *newState = TheGame->currentState;
			if (!newState->initialized) {
				newState->Init(currentState);
				newState->initialized = true;
			}
			if (newState->OnEnter)
				newState->OnEnter(currentState);
			currentState = newState;
		}

		//Swap Buffers
		if(frame&1) { drawingSurface=&frame2; SetFrameBuffer(ADDR_FRAMEBUFFER1); }
		else { drawingSurface=&frame1; SetFrameBuffer(ADDR_FRAMEBUFFER2); }

		//Update and draw
		currentState->Update(currentTime - oldTime);
		currentState->Draw(drawingSurface);

		frame++;

		if (currentState != TheGame->currentState &&
			TheGame->currentState->OnLeave)
		{
			currentState->OnLeave(currentState);
		}
		//VSync
		WaitVBL();
	}
}
Exemple #4
0
int main(int argc, char *argv[])
{
    // Initialize the pseudo-random number generator.
    InitializeRandom();

    // Initialize FFT data.
    FFTSetup Setup = vDSP_create_fftsetup(Log2SampleLength, FFT_RADIX2);
    if (Setup == 0)
    {
        fprintf(stderr, "Error, unable to create FFT setup.\n");
        exit(EXIT_FAILURE);
    }

    /*	If there are no command-line arguments, prompt for keys
    	interactively.
    */
    if (argc <= 1)
    {
        // Process keys for the user until they are done.
        int c;
        while (1)
        {
            // Prompt the user.
            printf(
                "Please enter a key (one of 0-9, *, #, or A-D):  ");

            // Skip whitespace except newlines.
            do
                c = getchar();
            while (c != '\n' && isspace(c));

            // When there is a blank line or an EOF, quit.
            if (c == '\n' || c == EOF)
                break;

            // Look up the key in the table.
            FrequencyPair F = ConvertKeyToFrequencies(toupper(c));

            // If it is a valid key, demonstrate the FFT.
            if (F.Frequency[0] != 0)
                Demonstrate(Setup, F);

            // Skip anything else on the line.
            do
                c = getchar();
            while (c != EOF && c != '\n');

            // When the input ends, quit.  Otherwise, do more.
            if (c == EOF)
                break;
        }

        // Do not leave the cursor in the middle of a line.
        if (c != '\n')
            printf("\n");
    }

    // If there is one command line argument, process the keys in it.
    else if (argc == 2)
    {
        for (char *p = argv[1]; *p; ++p)
        {
            // Look up the key in the table.
            FrequencyPair F = ConvertKeyToFrequencies(toupper(*p));

            // If it is a valid key, demonstrate the FFT.
            if (F.Frequency[0] != 0)
            {
                printf("Simulating key %c.\n", *p);
                Demonstrate(Setup, F);
            }
            else
                fprintf(stderr,
                        "Error, key %c not recognized.\n", *p);
        }
    }

    // If there are too many arguments, print a usage message.
    else
    {
        fprintf(stderr,
                "Usage:  %s [telephone keys 0-9, #, *, or A-D]\n",
                argv[0]);
        exit(EXIT_FAILURE);
    }

    // Release resources.
    vDSP_destroy_fftsetup(Setup);

    return 0;
}