testing/icgen/random_verschillende_resoluties_N-GenIC/gadget3_64/run.c
void run(void)
{
  FILE *fd;

#ifdef RADIATIVE_RATES
  int ifunc;
#endif
  int stopflag = 0;
  char buf[200], stopfname[200], contfname[200];


  sprintf(stopfname, "%sstop", All.OutputDir);
  sprintf(contfname, "%scont", All.OutputDir);
  unlink(contfname);


  CPU_Step[CPU_MISC] += measure_time();


  do				/* main loop */
    {

      find_next_sync_point_and_drift();	/* find next synchronization point and drift particles to this time.
					 * If needed, this function will also write an output file
					 * at the desired time.
					 */

      every_timestep_stuff();	/* write some info to log-files */

#ifdef RADIATIVE_RATES
      ifunc = init_rad(All.Time);
#endif

#ifdef COOLING
      IonizeParams();		/* set UV background for the current time */
#endif

#ifdef COMPUTE_POTENTIAL_ENERGY
      if((All.Time - All.TimeLastStatistics) >= All.TimeBetStatistics)
	All.NumForcesSinceLastDomainDecomp = (long long) (1 + All.TotNumPart * All.TreeDomainUpdateFrequency);
#endif

      domain_Decomposition();	/* do domain decomposition if needed */


      compute_accelerations(0);	/* compute accelerations for 
				 * the particles that are to be advanced  
				 */

#ifdef INVARIANCETEST
      compare_partitions();
#endif

      /* check whether we want a full energy statistics */
      if((All.Time - All.TimeLastStatistics) >= All.TimeBetStatistics)
	{
#ifdef COMPUTE_POTENTIAL_ENERGY
	  compute_potential();
#endif
	  energy_statistics();	/* compute and output energy statistics */

	  All.TimeLastStatistics += All.TimeBetStatistics;
	}

      advance_and_find_timesteps();	/* 'kick' active particles in
					 * momentum space and compute new
					 * timesteps for them
					 */
      write_cpu_log();		/* produce some CPU usage info */

      All.NumCurrentTiStep++;

      /* Check whether we need to interrupt the run */
      if(ThisTask == 0)
	{
	  /* Is the stop-file present? If yes, interrupt the run. */
	  if((fd = fopen(stopfname, "r")))
	    {
	      fclose(fd);
	      stopflag = 1;
	      unlink(stopfname);
	    }

	  /* are we running out of CPU-time ? If yes, interrupt run. */
	  if(CPUThisRun > 0.85 * All.TimeLimitCPU)
	    {
	      printf("reaching time-limit. stopping.\n");
	      stopflag = 2;
	    }
	}

      MPI_Bcast(&stopflag, 1, MPI_INT, 0, MPI_COMM_WORLD);

      if(stopflag)
	{
	  restart(0);		/* write restart file */
	  MPI_Barrier(MPI_COMM_WORLD);

	  if(stopflag == 2 && ThisTask == 0)
	    {
	      if((fd = fopen(contfname, "w")))
		fclose(fd);
	    }

	  if(stopflag == 2 && All.ResubmitOn && ThisTask == 0)
	    {
	      close_outputfiles();
	      sprintf(buf, "%s", All.ResubmitCommand);
#ifndef NOCALLSOFSYSTEM
	      int ret;

	      ret = system(buf);
#endif
	    }
	  return;
	}

      /* is it time to write a regular restart-file? (for security) */
      if(ThisTask == 0)
	{
	  if((CPUThisRun - All.TimeLastRestartFile) >= All.CpuTimeBetRestartFile)
	    {
	      All.TimeLastRestartFile = CPUThisRun;
	      stopflag = 3;
	    }
	  else
	    stopflag = 0;
	}

      MPI_Bcast(&stopflag, 1, MPI_INT, 0, MPI_COMM_WORLD);

      if(stopflag == 3)
	{
	  restart(0);		/* write an occasional restart file */
	  stopflag = 0;
	}
    }
  while(All.Ti_Current < TIMEBASE && All.Time <= All.TimeMax);

  restart(0);

  savepositions(All.SnapshotFileCount++);	/* write a last snapshot
						 * file at final time (will
						 * be overwritten if
						 * All.TimeMax is increased
						 * and the run is continued)
						 */
#ifdef CHEMISTRY
  if(ThisTask == 0)
    {
      printf("Initial abundances: \n");
      printf("HI=%g, HII=%g, HeI=%g, HeII=%g, HeIII=%g \n",
	     SphP[1].HI, SphP[1].HII, SphP[1].HeI, SphP[1].HeII, SphP[1].HeIII);

      printf("HM=%g, H2I=%g, H2II=%g, elec=%g, %d\n",
	     SphP[1].HM, SphP[1].H2I, SphP[1].H2II, SphP[1].elec, P[1].ID);

      printf("x=%g, y=%g, z=%g, vx=%g, vy=%g, vz=%g, density=%g, entropy=%g\n",
	     P[N_gas - 1].Pos[0], P[N_gas - 1].Pos[1], P[N_gas - 1].Pos[2], P[N_gas - 1].Vel[0],
	     P[N_gas - 1].Vel[1], P[N_gas - 1].Vel[2], SphP[N_gas - 1].Density, SphP[N_gas - 1].Entropy);
    }
#endif
}
/*! This routine contains the main simulation loop that iterates over
 * single timesteps. The loop terminates when the cpu-time limit is
 * reached, when a `stop' file is found in the output directory, or
 * when the simulation ends because we arrived at TimeMax.
 */
This routine contains the main simulation loop that iterates over
single timesteps. The loop terminates when the cpu-time limit is
reached, when a `stop' file is found in the output directory, or
when the simulation ends because we arrived at TimeMax.
This routine contains the main simulation loop that iterates over single timesteps . The loop terminates when the cpu - time limit is reached when a ` stop ' file is found in the output directory or when the simulation ends because we arrived at TimeMax .
void run(void)
{
  FILE *fd;
#ifdef RADIATIVE_RATES
  int ifunc;
#endif
  int stopflag = 0;
  char buf[200], stopfname[200], contfname[200];
  sprintf(stopfname, "%sstop", All.OutputDir);
  sprintf(contfname, "%scont", All.OutputDir);
  unlink(contfname);
  CPU_Step[CPU_MISC] += measure_time();
  do				
    {
      find_next_sync_point_and_drift();	
      every_timestep_stuff();	
#ifdef RADIATIVE_RATES
      ifunc = init_rad(All.Time);
#endif
#ifdef COOLING
      IonizeParams();		
#endif
#ifdef COMPUTE_POTENTIAL_ENERGY
      if((All.Time - All.TimeLastStatistics) >= All.TimeBetStatistics)
	All.NumForcesSinceLastDomainDecomp = (long long) (1 + All.TotNumPart * All.TreeDomainUpdateFrequency);
#endif
      domain_Decomposition();	
      compute_accelerations(0);	
#ifdef INVARIANCETEST
      compare_partitions();
#endif
      if((All.Time - All.TimeLastStatistics) >= All.TimeBetStatistics)
	{
#ifdef COMPUTE_POTENTIAL_ENERGY
	  compute_potential();
#endif
	  energy_statistics();	
	  All.TimeLastStatistics += All.TimeBetStatistics;
	}
      advance_and_find_timesteps();	
      write_cpu_log();		
      All.NumCurrentTiStep++;
      if(ThisTask == 0)
	{
	  if((fd = fopen(stopfname, "r")))
	    {
	      fclose(fd);
	      stopflag = 1;
	      unlink(stopfname);
	    }
	  if(CPUThisRun > 0.85 * All.TimeLimitCPU)
	    {
	      printf("reaching time-limit. stopping.\n");
	      stopflag = 2;
	    }
	}
      MPI_Bcast(&stopflag, 1, MPI_INT, 0, MPI_COMM_WORLD);
      if(stopflag)
	{
	  restart(0);		
	  MPI_Barrier(MPI_COMM_WORLD);
	  if(stopflag == 2 && ThisTask == 0)
	    {
	      if((fd = fopen(contfname, "w")))
		fclose(fd);
	    }
	  if(stopflag == 2 && All.ResubmitOn && ThisTask == 0)
	    {
	      close_outputfiles();
	      sprintf(buf, "%s", All.ResubmitCommand);
#ifndef NOCALLSOFSYSTEM
	      int ret;
	      ret = system(buf);
#endif
	    }
	  return;
	}
      if(ThisTask == 0)
	{
	  if((CPUThisRun - All.TimeLastRestartFile) >= All.CpuTimeBetRestartFile)
	    {
	      All.TimeLastRestartFile = CPUThisRun;
	      stopflag = 3;
	    }
	  else
	    stopflag = 0;
	}
      MPI_Bcast(&stopflag, 1, MPI_INT, 0, MPI_COMM_WORLD);
      if(stopflag == 3)
	{
	  restart(0);		
	  stopflag = 0;
	}
    }
  while(All.Ti_Current < TIMEBASE && All.Time <= All.TimeMax);
  restart(0);
  savepositions(All.SnapshotFileCount++);	
#ifdef CHEMISTRY
  if(ThisTask == 0)
    {
      printf("Initial abundances: \n");
      printf("HI=%g, HII=%g, HeI=%g, HeII=%g, HeIII=%g \n",
	     SphP[1].HI, SphP[1].HII, SphP[1].HeI, SphP[1].HeII, SphP[1].HeIII);
      printf("HM=%g, H2I=%g, H2II=%g, elec=%g, %d\n",
	     SphP[1].HM, SphP[1].H2I, SphP[1].H2II, SphP[1].elec, P[1].ID);
      printf("x=%g, y=%g, z=%g, vx=%g, vy=%g, vz=%g, density=%g, entropy=%g\n",
	     P[N_gas - 1].Pos[0], P[N_gas - 1].Pos[1], P[N_gas - 1].Pos[2], P[N_gas - 1].Vel[0],
	     P[N_gas - 1].Vel[1], P[N_gas - 1].Vel[2], SphP[N_gas - 1].Density, SphP[N_gas - 1].Entropy);
    }
#endif
}
void run ( void ) { FILE * fd ; #ifdef RADIATIVE_RATES int ifunc ; #endif int stopflag = 0 ; char buf [ 200 ] , stopfname [ 200 ] , contfname [ 200 ] ; sprintf ( stopfname , " " , All . OutputDir ) ; sprintf ( contfname , " " , All . OutputDir ) ; unlink ( contfname ) ; CPU_Step [ CPU_MISC ] += measure_time ( ) ; do { find_next_sync_point_and_drift ( ) ; every_timestep_stuff ( ) ; #ifdef RADIATIVE_RATES ifunc = init_rad ( All . Time ) ; #endif #ifdef COOLING IonizeParams ( ) ; #endif #ifdef COMPUTE_POTENTIAL_ENERGY if ( ( All . Time - All . TimeLastStatistics ) >= All . TimeBetStatistics ) All . NumForcesSinceLastDomainDecomp = ( long long ) ( 1 + All . TotNumPart * All . TreeDomainUpdateFrequency ) ; #endif domain_Decomposition ( ) ; compute_accelerations ( 0 ) ; #ifdef INVARIANCETEST compare_partitions ( ) ; #endif if ( ( All . Time - All . TimeLastStatistics ) >= All . TimeBetStatistics ) { #ifdef COMPUTE_POTENTIAL_ENERGY compute_potential ( ) ; #endif energy_statistics ( ) ; All . TimeLastStatistics += All . TimeBetStatistics ; } advance_and_find_timesteps ( ) ; write_cpu_log ( ) ; All . NumCurrentTiStep ++ ; if ( ThisTask == 0 ) { if ( ( fd = fopen ( stopfname , " " ) ) ) { fclose ( fd ) ; stopflag = 1 ; unlink ( stopfname ) ; } if ( CPUThisRun > 0.85 * All . TimeLimitCPU ) { printf ( " \n " ) ; stopflag = 2 ; } } MPI_Bcast ( & stopflag , 1 , MPI_INT , 0 , MPI_COMM_WORLD ) ; if ( stopflag ) { restart ( 0 ) ; MPI_Barrier ( MPI_COMM_WORLD ) ; if ( stopflag == 2 && ThisTask == 0 ) { if ( ( fd = fopen ( contfname , " " ) ) ) fclose ( fd ) ; } if ( stopflag == 2 && All . ResubmitOn && ThisTask == 0 ) { close_outputfiles ( ) ; sprintf ( buf , " " , All . ResubmitCommand ) ; #ifndef NOCALLSOFSYSTEM int ret ; ret = system ( buf ) ; #endif } return ; } if ( ThisTask == 0 ) { if ( ( CPUThisRun - All . TimeLastRestartFile ) >= All . CpuTimeBetRestartFile ) { All . TimeLastRestartFile = CPUThisRun ; stopflag = 3 ; } else stopflag = 0 ; } MPI_Bcast ( & stopflag , 1 , MPI_INT , 0 , MPI_COMM_WORLD ) ; if ( stopflag == 3 ) { restart ( 0 ) ; stopflag = 0 ; } } while ( All . Ti_Current < TIMEBASE && All . Time <= All . TimeMax ) ; restart ( 0 ) ; savepositions ( All . SnapshotFileCount ++ ) ; #ifdef CHEMISTRY if ( ThisTask == 0 ) { printf ( " \n " ) ; printf ( " \n " , SphP [ 1 ] . HI , SphP [ 1 ] . HII , SphP [ 1 ] . HeI , SphP [ 1 ] . HeII , SphP [ 1 ] . HeIII ) ; printf ( " \n " , SphP [ 1 ] . HM , SphP [ 1 ] . H2I , SphP [ 1 ] . H2II , SphP [ 1 ] . elec , P [ 1 ] . ID ) ; printf ( " \n " , P [ N_gas - 1 ] . Pos [ 0 ] , P [ N_gas - 1 ] . Pos [ 1 ] , P [ N_gas - 1 ] . Pos [ 2 ] , P [ N_gas - 1 ] . Vel [ 0 ] , P [ N_gas - 1 ] . Vel [ 1 ] , P [ N_gas - 1 ] . Vel [ 2 ] , SphP [ N_gas - 1 ] . Density , SphP [ N_gas - 1 ] . Entropy ) ; } #endif }
This routine contains the main simulation loop that iterates over
 single timesteps.
This routine contains the main simulation loop that iterates over single timesteps .
/* main loop */ /* find next synchronization point and drift particles to this time.
					 * If needed, this function will also write an output file
					 * at the desired time.
					 */ /* write some info to log-files */ /* set UV background for the current time */ /* do domain decomposition if needed */ /* compute accelerations for 
				 * the particles that are to be advanced  
				 */ /* check whether we want a full energy statistics */ /* compute and output energy statistics */ /* 'kick' active particles in
					 * momentum space and compute new
					 * timesteps for them
					 */ /* produce some CPU usage info */ /* Check whether we need to interrupt the run */ /* Is the stop-file present? If yes, interrupt the run. */ /* are we running out of CPU-time ? If yes, interrupt run. */ /* write restart file */ /* is it time to write a regular restart-file? (for security) */ /* write an occasional restart file */ /* write a last snapshot
						 * file at final time (will
						 * be overwritten if
						 * All.TimeMax is increased
						 * and the run is continued)
						 */