Example #1
0
Full_Run(int L,double m2_avg[],double m_avg[],int l){
    Initialize(S,L);
    for(t=0;t<T_EQ*L*L;t++)Sweep(S,m_sum,prob,t,L);
    for(t=0;t<T_MEAS*L*L;t++){
        m_sum[t] = 0;
        Sweep(S,m_sum,prob,t,L);
        m2_avg[l] +=  m_sum[t]*m_sum[t];
        m_avg[l] += m_sum[t];}
}
Example #2
0
MeshEvolution::MeshEvolution(Mesh &mesh) : mesh(mesh)
{
    // generate in-between balls using hax
    foreach (const Ball &ball, mesh.balls)
    {
        // get the parent ball
        if (ball.parentIndex == -1) {
            sweeps += Sweep(ball, ball);
        } else {
            const Ball &parent = mesh.balls[ball.parentIndex];
            sweeps += Sweep(ball, parent);
        }
    }
}
Example #3
0
int main( int argc, char ** argv )
{
   walberla::Environment env( argc, argv );

   // create blocks
   shared_ptr< StructuredBlockForest > blocks = blockforest::createUniformBlockGrid(
            uint_c( 3), uint_c(2), uint_c( 4), // number of blocks in x,y,z direction
            uint_c(10), uint_c(8), uint_c(12), // how many cells per block (x,y,z)
            real_c(0.5),                       // dx: length of one cell in physical coordinates
            false,                             // one block per process? - "false" means all blocks to one process
            false, false, false );             // no periodicity

   // add a field to all blocks - and store the returned block data ID which is needed to access the field
   BlockDataID fieldID = blocks->addStructuredBlockData< Field<real_t,1> >( &createFields, "My Field" );

   // iterate all blocks and initialize with random values
   for( auto blockIterator = blocks->begin(); blockIterator != blocks->end(); ++blockIterator )
   {
      IBlock & currentBlock = *blockIterator;

      // get the field stored on the current block
      Field<real_t,1> * field = currentBlock.getData< Field<real_t,1> >( fieldID );

      // iterate the field and set random values
      for( auto iter = field->begin(); iter != field->end(); ++iter )
         *iter = real_c( rand() % ARBITRARY_VALUE );
   }

   // create time loop
   const uint_t numberOfTimesteps = uint_c(10); // number of time steps for non-gui runs
   SweepTimeloop timeloop( blocks, numberOfTimesteps );

   // registering the function sweep
   auto pointerToTwoArgFunction = & simpleSweep;
   auto pointerToOneArgFunction = std::bind( pointerToTwoArgFunction, std::placeholders::_1, fieldID );
   timeloop.add() << Sweep( pointerToOneArgFunction, "BogusAlgorithm" );

   // registering the class sweep
   timeloop.add() << Sweep( SimpleSweep(fieldID), "BogusAlgorithmButNowAsFunctor" );

   // two sweeps were registered, so both are executed in each time step

   GUI gui( timeloop, blocks, argc, argv );
   gui.run();

   return EXIT_SUCCESS;
}
Example #4
0
	void GCAlloc::SweepNeedsSweeping()
	{
		GCBlock* next;
		for (GCBlock* b = m_needsSweeping; b != NULL; b = next)
		{
			next = b->nextFree;	
			Sweep(b);
		}
		GCAssert(m_needsSweeping == NULL);
	}
Example #5
0
	void GCAlloc::ClearMarks()
	{
		for ( GCBlock *block=m_firstBlock, *next ; block ; block=next ) {
			next = Next(block);
			
			if (block->needsSweeping && Sweep(block)) 
				continue;

			ClearMarks(block);
		}
	}	
/* ------------------------------------------------------------------------------------ */
void CAudioStream::Tick(geFloat dwTicks)
{
	geEntity_EntitySet *pSet;
	geEntity *pEntity;
	geVec3d PlayerPos;

	if(m_nStreamerCount == 0)
		return;										// No streamers in world, bail early

	// Now scan for StreamingAudioProxy entities
	pSet = geWorld_GetEntitySet(CCD->World(), "StreamingAudioProxy");

	if(!pSet)
		return;										// Don't waste CPU time.

	// Clean up any non-playing streams
	Sweep();

	// Ok, go through and see if we need to trigger playback.
	PlayerPos = CCD->Player()->Position();			// Get player position

	for(pEntity=geEntity_EntitySetGetNextEntity(pSet, NULL); pEntity;
	    pEntity=geEntity_EntitySetGetNextEntity(pSet, pEntity))
	{
		StreamingAudioProxy *pProxy = (StreamingAudioProxy*)geEntity_GetUserData(pEntity);

		if(pProxy->bActive == false)
			continue;								// Not active, ignore it

		// changed QD 12/15/05
		//if(geVec3d_DistanceBetween(&pProxy->origin, &PlayerPos) > pProxy->Range)
		//	continue;	// Too far away
		geVec3d temp;
		geVec3d_Subtract(&pProxy->origin, &PlayerPos, &temp);

		if(geVec3d_DotProduct(&temp, &temp) > pProxy->Range*pProxy->Range)
			continue;	// Too far away
		// end change

		// Check to see if we've waited long enough before triggering this
		// ..from the last time.
		if(CCD->FreeRunningCounter() < (DWORD)(pProxy->LastTimeTriggered + (pProxy->SleepTime*1000)))
			continue;								// No more often than every <n> seconds.

		// Ok, we're close enough and it's time.  Trigger it!
		Play(pProxy->szStreamFile, pProxy->bLoops, true);

		// If this is a one-shot, kill any hope of reactivation.
		if(pProxy->bOneShot == GE_TRUE)
			pProxy->bActive = false;				// Turn it off!
	}

	return;
}
int Convex_Hull_2D(int Nb, const GLpoint* Pts, int* Ind) 
{ 
	int n;
	if (Nb<=2) 
		return Nb; 
	Sort_Pts = Pts; // nasty. Only to overcome qsort()'s API  
	// First sweep, to find lower boundary. 
	// Points are sorted right to left.

		
	qsort(Ind, Nb, sizeof(int), Cmp_Lo); 
	n = Sweep(Nb, Pts, Ind);  
	// Second sweep, to find upper boundary 
	// Actually, we sort the remaining [n..Nb] partition in 
	// reverse order (left to right) -> The sweep loop is the same.  
	Ind[Nb] = Ind[0]; 
	// Close cycle with leftmost point 
	//qsort(Ind+n, Nb-n, sizeof(int), Cmp_Hi); 
	n += Sweep(Nb+1-n, Pts, Ind+n); 
	Ind[n] = Ind[Nb]; // restore 
	return n; 
	return 1;
 }
Example #8
0
void GarbageCollector::PerformGC(RunTimeStack &s)
	{
	// Perform mark-and-sweep garbage collection.  We
	// follow every pointer in every activation record
	// in the RunTimeStack, marking all Objects found.
	// Before marking an Object, we make sure it is not
	// already marked, so we don't enter an infinite loop.

	// Then we sweep once through the ObjectList.  For
	// each Object in the ObjectList, if it is not marked,
	// we remove it from the list and delete it; otherwise,
	// we unmark it so it is ready for the next round of
	// mark-and-sweep.

	Mark(s);
	Sweep(s);
	}
Example #9
0
void CollectGarbage(VM* vm)
{
	if(vm->debug)
		printf("collecting garbage...\n");
	int numObjects = vm->numObjects;
	MarkAll(vm);
	if(vm->debug)
		printf("marked all objects\n");
	Sweep(vm);
	if(vm->debug)
		printf("cleaned objects\n");
	vm->maxObjectsUntilGc = vm->numObjects * 2 + vm->numGlobals;

	if(vm->debug)
	{
		printf("objects before collection: %i\n"
			   "objects after collection: %i\n", numObjects, vm->numObjects);
	}
}
Example #10
0
int ExecCommand(tGame *game, tCommand * command)
{
	int i = command->command_ref;
	int res;

	switch (i)
	{
		case COMMAND_SWEEP:
			res = Sweep(game, command);
			if (game->gametype != GAMETYPE_INDIVIDUAL_NOLIMIT)
				game->moves--;
			break;
		
		case COMMAND_FLAG:
			if (!(command->flag.is_range))
			{	
				res = DoFlagUnflag(game, command, DO_FLAG);
				if (game->gametype != GAMETYPE_INDIVIDUAL_NOLIMIT)
					game->moves--;
			}	
			else
			{
				res = FlagRange(game, command, DO_FLAG);
				if (game->gametype != GAMETYPE_INDIVIDUAL_NOLIMIT)
					game->moves-= res;
			}	
			break;
		
		case COMMAND_UNFLAG:
			if (!(command->flag.is_range))
			{
				res = DoFlagUnflag(game, command, DO_UNFLAG);
				if (game->gametype != GAMETYPE_INDIVIDUAL_NOLIMIT)
					game->moves--;
			}	
			else
			{
				res = FlagRange(game, command, DO_UNFLAG);
				if (game->gametype != GAMETYPE_INDIVIDUAL_NOLIMIT)
					game->moves-= res;
			}	
			break;
		
		case COMMAND_QUERY:
			res = Query(&game->hiddenboard, command);
			break;

		case COMMAND_SAVE:
			res = WriteSaveFile(game, command->save_filename);
			break;
		
		case COMMAND_QUIT:
			Quit(game, command);
			exit(0);
			break;
		
		case COMMAND_UNDO:
			if (command->undo.can_undo && game->undos)
			{
				Undo(game, &command->undo);
				game->undos--;
				if (game->gametype != GAMETYPE_INDIVIDUAL_NOLIMIT)
					game->moves--;
			}
			else
				command->undo.undo_error = TRUE;
			break;


	}

	if (res == SWEEP_MINE && i == COMMAND_SWEEP)
	{
		if (game->undos)
		{	
			if (game->gametype == GAMETYPE_INDIVIDUAL_NOLIMIT)
				AskUndo(game, &command->undo);
			else if (game->moves)
				AskUndo(game, &command->undo);
			else
				game->gamestate = GAMESTATE_LOSE;
		}
		else
			game->gamestate = GAMESTATE_LOSE;
	}	
	return res;
}
Example #11
0
std::vector<mpz_class> Sieve::Factor()
{
	unsigned long int first = 0;
	int iter = 0;

#ifdef PRINT
					std::cout << "beginning to factor"<< std::endl;
					std::cout << "num smooth required: " << numsmoothrequired << std::endl;
					std::cout << "MAXSWEEPS: " << MAXSWEEPS << std::endl;
#endif
	while (numsmooth < numsmoothrequired && iter++ < MAXSWEEPS)
	{
		Sweep(first);
		updateThreshhold();
		first += SIEVESIZE;
	}
#ifdef PRINT
					std::cout << iter <<  " sweeps done"<< std::endl;
#endif
	std::vector<mpz_class> factors;
	std::vector<int> nullvec;
#ifdef PRINT
					std::cout << "num smooth found: " << numsmooth << std::endl;
					std::cout << "num tried: " << numtried << std::endl;
#endif
	if (numsmooth == numsmoothrequired)
	{
		mpz_class a, b, ab, factor1;
		matrixptr->gauss();
		for (int i = 0; i < 20 && matrixptr->hasMoreSolutions(); ++i)
		{
			nullvec = matrixptr->getNextSolution();
			a = 1;
			b = 1;
			for (int j = 0; j < nullvec.size(); j++)
			{
				if (nullvec[j] == 1)
				{
					a = (a * smooth_x[j]);
					b = (b * smooth_y[j]);
				}
			}
			mpz_root(b.get_mpz_t(), b.get_mpz_t(), 2);
			ab = a - b;
			mpz_abs(ab.get_mpz_t(), ab.get_mpz_t());
			mpz_gcd(factor1.get_mpz_t(), ab.get_mpz_t(), N.get_mpz_t());

			if (factor1 != 1 && factor1 != N)
			{
				bool exists = false;
				for (std::vector<mpz_class>::iterator it = factors.begin(); it != factors.end(); ++it)
				{
					if ((*it) == factor1)
					{
						exists = true;
						break;
					}
				}
				if (!exists)
				{
					factors.push_back(factor1);
					i = 0;
				}
			}
		}
	}
	return factors;
}
Example #12
0
void Registry::MarkAndSweep(Object root)
{
	Mark(root);
	Sweep();
}
Example #13
0
	void* GCAlloc::Alloc(int flags)
#endif
	{
		GCAssertMsg(((size_t)m_itemSize >= size), "allocator itemsize too small");

		// Allocation must be signalled before we allocate because no GC work must be allowed to
		// come between an allocation and an initialization - if it does, we may crash, as 
		// GCFinalizedObject subclasses may not have a valid vtable, but the GC depends on them
		// having it.  In principle we could signal allocation late but only set the object
		// flags after signaling, but we might still cause trouble for the profiler, which also
		// depends on non-interruptibility.

		m_gc->SignalAllocWork(m_itemSize);
		
		GCBlock* b = m_firstFree;
	start:
		if (b == NULL) {
			if (m_needsSweeping && !m_gc->collecting) {
				Sweep(m_needsSweeping);
				b = m_firstFree;
				goto start;
			}
			
			bool canFail = (flags & GC::kCanFail) != 0;
			CreateChunk(canFail);
			b = m_firstFree;
			if (b == NULL) {
				GCAssert(canFail);
				return NULL;
			}
		}
		
		GCAssert(!b->needsSweeping);
		GCAssert(b == m_firstFree);
		GCAssert(b && !b->IsFull());
		
		void *item;
		if(b->firstFree) {
			item = b->firstFree;
			b->firstFree = *((void**)item);
			// clear free list pointer, the rest was zero'd in free
			*(intptr_t*) item = 0;
#ifdef MMGC_MEMORY_INFO
			//check for writes on deleted memory
			VerifyFreeBlockIntegrity(item, b->size);
#endif
		} else {
			item = b->nextItem;
			if(((uintptr_t)((char*)item + b->size) & 0xfff) != 0) {
				b->nextItem = (char*)item + b->size;
			} else {
				b->nextItem = NULL;
			}
		}

		// set up bits, items start out white and whether they need finalization
		// is determined by the caller

		// make sure we ended up in the right place
		GCAssert(((flags&GC::kContainsPointers) != 0) == ContainsPointers());

		// this assumes what we assert
		GCAssert((unsigned long)GC::kFinalize == (unsigned long)GCAlloc::kFinalize);
		
		int index = GetIndex(b, item);
		GCAssert(index >= 0);
		Clear4BitsAndSet(b, index, flags & kFinalize);

		b->numItems++;
#ifdef MMGC_MEMORY_INFO
		m_numAlloc++;
#endif

		// If we're out of free items, be sure to remove ourselves from the
		// list of blocks with free items.  TODO Minor optimization: when we
		// carve an item off the end of the block, we don't need to check here
		// unless we just set b->nextItem to NULL.

		if (b->IsFull()) {
			m_firstFree = b->nextFree;
			b->nextFree = NULL;
			GCAssert(b->prevFree == NULL);

			if (m_firstFree)
				m_firstFree->prevFree = 0;
		}

		// prevent mid-collection (ie destructor) allocations on un-swept pages from
		// getting swept.  If the page is finalized and doesn't need sweeping we don't want
		// to set the mark otherwise it will be marked when we start the next marking phase
		// and write barriers won't fire (since its black)
		if(m_gc->collecting)
		{ 
			if((b->finalizeState != m_gc->finalizedValue) || b->needsSweeping)
				SetBit(b, index, kMark);
		}

		GCAssert((uintptr_t(item) & ~0xfff) == (uintptr_t) b);
		GCAssert((uintptr_t(item) & 7) == 0);

#ifdef MMGC_HOOKS
		GCHeap* heap = GCHeap::GetGCHeap();
		if(heap->HooksEnabled())
		{
			size_t userSize = m_itemSize - DebugSize();
#ifdef MMGC_MEMORY_PROFILER
			m_totalAskSize += size;
			heap->AllocHook(GetUserPointer(item), size, userSize);
#else
			heap->AllocHook(GetUserPointer(item), 0, userSize);
#endif
		}
#endif

		return item;
	}
Example #14
0
void entradadatos(int sig){
    int d=1;
    char buffer[128];
    liberabloqueos();
    read(0,buffer,128);
	tipomensaje=analizamensaje(buffer);
	//fprintf(stderr,"%s\n",buffer);fflush(stderr);fsync(fileno(stderr));
        switch(tipomensaje){
	case RADAR:
	    sscanf(buffer,"Radar %lf %i %lf",&distancia,&tipoobjeto,&angulo);
	    switch(tipoobjeto){
	    case ROBOT:
                  DisparoRobot(distancia);
		break;
	    case SHOT:
                 ParoDisparo(angulo,distancia);
		break;
	    case WALL:
                 EsquivoPared(distancia);
		break;
	    case COOKIE:
                 APorGalleta(angulo);
		break;
	    case MINE:
		EsquivoMina(angulo);
	    }
	    break;
	case COLLISION:
	    sscanf(buffer,"Collision %i %lf",&tipoobjeto,&angulo);
	    switch(tipoobjeto){
	    case WALL:
	        if(i-tiempocolision>20){
		    Accelerate(-0.5);
		    Brake(1);
		    RotateAmount(1,666.0,angulo+180);
	        }
	        tiempocolision=i;
		Accelerate(2.0);
		break;
	    case ROBOT:
		RotateAmount(1,666,angulo+15);
                break;
	    case SHOT:
                RotateAmount(1,666,angulo+15);
                break;
	    case COOKIE:
                aquemededico=BUSCANDOANILLO;
                break;
	    case MINE:
                break;
	    }
            break;
	case INITIALIZE:
	    if(!inicializado){
		printf("Print Ash nazg durbatuluuk, ash nazg gimbatul, ash nazg trakatuluuk agh burzum-ishi krimpatul!\n");fflush(stdout);fsync(fileno(stdout));
		printf("Name sauron\n");fflush(stdout);fsync(fileno(stdout));
		printf("Colour 00F0F0 010F0F\n");fflush(stdout);fsync(fileno(stdout));
		inicializado=1;
	    }
	    break;
	case ENERGY:
	    sscanf(buffer,"Energy %lf",&energia);
            energiadisparo=30;
	    if(energia<5){
                energiadisparo=0;
	    }
            break;
	case ROBOT_INFO:
	    break;
	case ROTATION_REACHED:
            Accelerate(2);
	    Sweep(6,45.2,-0.255,0.25); // Si sabia cuanto girar es que busco algo concreto.
	    break;
	case WARNING:
	    break;
	case 666:
            sleep(1);
            break;
    }
    if(tipomensaje==GAME_STARTS){
	while(1){
            i++;
	    switch (aquemededico){
	    case BUSCANDOANILLO:
		Accelerate(2.0);
		Rotate(1,2.0);
		if(!(i%300)){
                    Brake(0.7);
		    RotateAmount(1,666.0,90.0);
		}else if(!(i%150)){
                    Brake(0.7);
		    RotateAmount(1,666.0,-90.0);
		}
		break;
	    case GALLETAS:
		Sweep(6,45.2,-0.75,0.75);
		if (!(time(NULL)-tiempogalleta)) {
		    aquemededico=BUSCANDOANILLO;
		}
		break;
	    case MATAR:
                Sweep(6,45.2,-0.01,0.01);
		break;
	    }
	    liberabloqueos();
	    sleep(1);
	}
    }
}