testing/icgen/random_verschillende_resoluties_N-GenIC/gadget3_64/run.c
void find_next_sync_point_and_drift(void)
{
  int n, i, prev, dt_bin, ti_next_for_bin, ti_next_kick, ti_next_kick_global;
  long long numforces2;
  double timeold;

  timeold = All.Time;

  /* find the next kick time */
  for(n = 0, ti_next_kick = TIMEBASE; n < TIMEBINS; n++)
    {
      if(TimeBinCount[n])
	{
	  if(n > 0)
	    {
	      dt_bin = (1 << n);
	      ti_next_for_bin = (All.Ti_Current / dt_bin) * dt_bin + dt_bin;	/* next kick time for this timebin */
	    }
	  else
	    {
	      dt_bin = 0;
	      ti_next_for_bin = All.Ti_Current;
	    }

	  if(ti_next_for_bin < ti_next_kick)
	    ti_next_kick = ti_next_for_bin;
	}
    }

  MPI_Allreduce(&ti_next_kick, &ti_next_kick_global, 1, MPI_INT, MPI_MIN, MPI_COMM_WORLD);


  while(ti_next_kick_global >= All.Ti_nextoutput && All.Ti_nextoutput >= 0)
    {
      All.Ti_Current = All.Ti_nextoutput;

      if(All.ComovingIntegrationOn)
	All.Time = All.TimeBegin * exp(All.Ti_Current * All.Timebase_interval);
      else
	All.Time = All.TimeBegin + All.Ti_Current * All.Timebase_interval;
#ifdef TIMEDEPGRAV
      All.G = All.Gini * dGfak(All.Time);
#endif

      move_particles(All.Ti_nextoutput);

      CPU_Step[CPU_DRIFT] += measure_time();

#ifdef OUTPUTPOTENTIAL
#if !defined(EVALPOTENTIAL) || (defined(EVALPOTENTIAL) && defined(RECOMPUTE_POTENTIAL_ON_OUTPUT))
      All.NumForcesSinceLastDomainDecomp = (long long) (1 + All.TotNumPart * All.TreeDomainUpdateFrequency);
      domain_Decomposition();
      compute_potential();
#endif
#endif


      savepositions(All.SnapshotFileCount++);	/* write snapshot file */

      All.Ti_nextoutput = find_next_outputtime(All.Ti_nextoutput + 1);
    }

  All.Ti_Current = ti_next_kick_global;

  if(All.ComovingIntegrationOn)
    All.Time = All.TimeBegin * exp(All.Ti_Current * All.Timebase_interval);
  else
    All.Time = All.TimeBegin + All.Ti_Current * All.Timebase_interval;
#ifdef TIMEDEPGRAV
  All.G = All.Gini * dGfak(All.Time);
#endif

  All.TimeStep = All.Time - timeold;


  /* mark the bins that will be active */
  for(n = 1, TimeBinActive[0] = 1, NumForceUpdate = TimeBinCount[0]; n < TIMEBINS; n++)
    {
      dt_bin = (1 << n);

      if((ti_next_kick_global % dt_bin) == 0)
	{
	  TimeBinActive[n] = 1;
	  NumForceUpdate += TimeBinCount[n];
	}
      else
	TimeBinActive[n] = 0;
    }

  sumup_large_ints(1, &NumForceUpdate, &GlobNumForceUpdate);

  if(GlobNumForceUpdate == All.TotNumPart)
    Flag_FullStep = 1;
  else
    Flag_FullStep = 0;

  All.NumForcesSinceLastDomainDecomp += GlobNumForceUpdate;


  FirstActiveParticle = -1;

  for(n = 0, prev = -1; n < TIMEBINS; n++)
    {
      if(TimeBinActive[n])
	{
	  for(i = FirstInTimeBin[n]; i >= 0; i = NextInTimeBin[i])
	    {
	      if(prev == -1)
		FirstActiveParticle = i;

	      if(prev >= 0)
		NextActiveParticle[prev] = i;

	      prev = i;
	    }
	}
    }

  if(prev >= 0)
    NextActiveParticle[prev] = -1;


#ifdef PERMUTATAION_OPTIMIZATION
  generate_permutation_in_active_list();
#endif

  /* drift the active particles, others will be drifted on the fly if needed */

  for(i = FirstActiveParticle, NumForceUpdate = 0; i >= 0; i = NextActiveParticle[i])
    {
      drift_particle(i, All.Ti_Current);

      NumForceUpdate++;
    }

  sumup_large_ints(1, &NumForceUpdate, &numforces2);
  if(GlobNumForceUpdate != numforces2)
    {
      printf("terrible\n");
      endrun(2);
    }


  CPU_Step[CPU_DRIFT] += measure_time();
}
/*! This function finds the next synchronization point of the system
 * (i.e. the earliest point of time any of the particles needs a force
 * computation), and drifts the system to this point of time.  If the
 * system dirfts over the desired time of a snapshot file, the
 * function will drift to this moment, generate an output, and then
 * resume the drift.
 */
This function finds the next synchronization point of the system
, and drifts the system to this point of time.  If the
system dirfts over the desired time of a snapshot file, the
function will drift to this moment, generate an output, and then
resume the drift.
This function finds the next synchronization point of the system and drifts the system to this point of time . If the system dirfts over the desired time of a snapshot file the function will drift to this moment generate an output and then resume the drift .
void find_next_sync_point_and_drift(void)
{
  int n, i, prev, dt_bin, ti_next_for_bin, ti_next_kick, ti_next_kick_global;
  long long numforces2;
  double timeold;
  timeold = All.Time;
  for(n = 0, ti_next_kick = TIMEBASE; n < TIMEBINS; n++)
    {
      if(TimeBinCount[n])
	{
	  if(n > 0)
	    {
	      dt_bin = (1 << n);
	      ti_next_for_bin = (All.Ti_Current / dt_bin) * dt_bin + dt_bin;	
	    }
	  else
	    {
	      dt_bin = 0;
	      ti_next_for_bin = All.Ti_Current;
	    }
	  if(ti_next_for_bin < ti_next_kick)
	    ti_next_kick = ti_next_for_bin;
	}
    }
  MPI_Allreduce(&ti_next_kick, &ti_next_kick_global, 1, MPI_INT, MPI_MIN, MPI_COMM_WORLD);
  while(ti_next_kick_global >= All.Ti_nextoutput && All.Ti_nextoutput >= 0)
    {
      All.Ti_Current = All.Ti_nextoutput;
      if(All.ComovingIntegrationOn)
	All.Time = All.TimeBegin * exp(All.Ti_Current * All.Timebase_interval);
      else
	All.Time = All.TimeBegin + All.Ti_Current * All.Timebase_interval;
#ifdef TIMEDEPGRAV
      All.G = All.Gini * dGfak(All.Time);
#endif
      move_particles(All.Ti_nextoutput);
      CPU_Step[CPU_DRIFT] += measure_time();
#ifdef OUTPUTPOTENTIAL
#if !defined(EVALPOTENTIAL) || (defined(EVALPOTENTIAL) && defined(RECOMPUTE_POTENTIAL_ON_OUTPUT))
      All.NumForcesSinceLastDomainDecomp = (long long) (1 + All.TotNumPart * All.TreeDomainUpdateFrequency);
      domain_Decomposition();
      compute_potential();
#endif
#endif
      savepositions(All.SnapshotFileCount++);	
      All.Ti_nextoutput = find_next_outputtime(All.Ti_nextoutput + 1);
    }
  All.Ti_Current = ti_next_kick_global;
  if(All.ComovingIntegrationOn)
    All.Time = All.TimeBegin * exp(All.Ti_Current * All.Timebase_interval);
  else
    All.Time = All.TimeBegin + All.Ti_Current * All.Timebase_interval;
#ifdef TIMEDEPGRAV
  All.G = All.Gini * dGfak(All.Time);
#endif
  All.TimeStep = All.Time - timeold;
  for(n = 1, TimeBinActive[0] = 1, NumForceUpdate = TimeBinCount[0]; n < TIMEBINS; n++)
    {
      dt_bin = (1 << n);
      if((ti_next_kick_global % dt_bin) == 0)
	{
	  TimeBinActive[n] = 1;
	  NumForceUpdate += TimeBinCount[n];
	}
      else
	TimeBinActive[n] = 0;
    }
  sumup_large_ints(1, &NumForceUpdate, &GlobNumForceUpdate);
  if(GlobNumForceUpdate == All.TotNumPart)
    Flag_FullStep = 1;
  else
    Flag_FullStep = 0;
  All.NumForcesSinceLastDomainDecomp += GlobNumForceUpdate;
  FirstActiveParticle = -1;
  for(n = 0, prev = -1; n < TIMEBINS; n++)
    {
      if(TimeBinActive[n])
	{
	  for(i = FirstInTimeBin[n]; i >= 0; i = NextInTimeBin[i])
	    {
	      if(prev == -1)
		FirstActiveParticle = i;
	      if(prev >= 0)
		NextActiveParticle[prev] = i;
	      prev = i;
	    }
	}
    }
  if(prev >= 0)
    NextActiveParticle[prev] = -1;
#ifdef PERMUTATAION_OPTIMIZATION
  generate_permutation_in_active_list();
#endif
  for(i = FirstActiveParticle, NumForceUpdate = 0; i >= 0; i = NextActiveParticle[i])
    {
      drift_particle(i, All.Ti_Current);
      NumForceUpdate++;
    }
  sumup_large_ints(1, &NumForceUpdate, &numforces2);
  if(GlobNumForceUpdate != numforces2)
    {
      printf("terrible\n");
      endrun(2);
    }
  CPU_Step[CPU_DRIFT] += measure_time();
}
void find_next_sync_point_and_drift ( void ) { int n , i , prev , dt_bin , ti_next_for_bin , ti_next_kick , ti_next_kick_global ; long long numforces2 ; double timeold ; timeold = All . Time ; for ( n = 0 , ti_next_kick = TIMEBASE ; n < TIMEBINS ; n ++ ) { if ( TimeBinCount [ n ] ) { if ( n > 0 ) { dt_bin = ( 1 << n ) ; ti_next_for_bin = ( All . Ti_Current / dt_bin ) * dt_bin + dt_bin ; } else { dt_bin = 0 ; ti_next_for_bin = All . Ti_Current ; } if ( ti_next_for_bin < ti_next_kick ) ti_next_kick = ti_next_for_bin ; } } MPI_Allreduce ( & ti_next_kick , & ti_next_kick_global , 1 , MPI_INT , MPI_MIN , MPI_COMM_WORLD ) ; while ( ti_next_kick_global >= All . Ti_nextoutput && All . Ti_nextoutput >= 0 ) { All . Ti_Current = All . Ti_nextoutput ; if ( All . ComovingIntegrationOn ) All . Time = All . TimeBegin * exp ( All . Ti_Current * All . Timebase_interval ) ; else All . Time = All . TimeBegin + All . Ti_Current * All . Timebase_interval ; #ifdef TIMEDEPGRAV All . G = All . Gini * dGfak ( All . Time ) ; #endif move_particles ( All . Ti_nextoutput ) ; CPU_Step [ CPU_DRIFT ] += measure_time ( ) ; #ifdef OUTPUTPOTENTIAL #if ! defined ( EVALPOTENTIAL ) || ( defined ( EVALPOTENTIAL ) && defined ( RECOMPUTE_POTENTIAL_ON_OUTPUT ) ) All . NumForcesSinceLastDomainDecomp = ( long long ) ( 1 + All . TotNumPart * All . TreeDomainUpdateFrequency ) ; domain_Decomposition ( ) ; compute_potential ( ) ; #endif #endif savepositions ( All . SnapshotFileCount ++ ) ; All . Ti_nextoutput = find_next_outputtime ( All . Ti_nextoutput + 1 ) ; } All . Ti_Current = ti_next_kick_global ; if ( All . ComovingIntegrationOn ) All . Time = All . TimeBegin * exp ( All . Ti_Current * All . Timebase_interval ) ; else All . Time = All . TimeBegin + All . Ti_Current * All . Timebase_interval ; #ifdef TIMEDEPGRAV All . G = All . Gini * dGfak ( All . Time ) ; #endif All . TimeStep = All . Time - timeold ; for ( n = 1 , TimeBinActive [ 0 ] = 1 , NumForceUpdate = TimeBinCount [ 0 ] ; n < TIMEBINS ; n ++ ) { dt_bin = ( 1 << n ) ; if ( ( ti_next_kick_global % dt_bin ) == 0 ) { TimeBinActive [ n ] = 1 ; NumForceUpdate += TimeBinCount [ n ] ; } else TimeBinActive [ n ] = 0 ; } sumup_large_ints ( 1 , & NumForceUpdate , & GlobNumForceUpdate ) ; if ( GlobNumForceUpdate == All . TotNumPart ) Flag_FullStep = 1 ; else Flag_FullStep = 0 ; All . NumForcesSinceLastDomainDecomp += GlobNumForceUpdate ; FirstActiveParticle = -1 ; for ( n = 0 , prev = -1 ; n < TIMEBINS ; n ++ ) { if ( TimeBinActive [ n ] ) { for ( i = FirstInTimeBin [ n ] ; i >= 0 ; i = NextInTimeBin [ i ] ) { if ( prev == -1 ) FirstActiveParticle = i ; if ( prev >= 0 ) NextActiveParticle [ prev ] = i ; prev = i ; } } } if ( prev >= 0 ) NextActiveParticle [ prev ] = -1 ; #ifdef PERMUTATAION_OPTIMIZATION generate_permutation_in_active_list ( ) ; #endif for ( i = FirstActiveParticle , NumForceUpdate = 0 ; i >= 0 ; i = NextActiveParticle [ i ] ) { drift_particle ( i , All . Ti_Current ) ; NumForceUpdate ++ ; } sumup_large_ints ( 1 , & NumForceUpdate , & numforces2 ) ; if ( GlobNumForceUpdate != numforces2 ) { printf ( " \n " ) ; endrun ( 2 ) ; } CPU_Step [ CPU_DRIFT ] += measure_time ( ) ; }
This function finds the next synchronization point of the system
 (i.e.
This function finds the next synchronization point of the system ( i . e .
/* find the next kick time */ /* next kick time for this timebin */ /* write snapshot file */ /* mark the bins that will be active */ /* drift the active particles, others will be drifted on the fly if needed */