/*! 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; int stopflag = 0; char stopfname[200], contfname[200]; double t0, t1, tstart, tend, nh_local, nh_max, tot_dens_max, nh_max_nosink, tot_nh_max_nosink; int nsinks, i, j, k; /*SINKS*/ double a3, a3inv, hubble_param, hubble_param2, Temp, SinkCriticalDensity; sprintf(stopfname, "%sstop", All.OutputDir); sprintf(contfname, "%scont", All.OutputDir); unlink(contfname); do /* main loop */ { t0 = second(); if(All.ComovingIntegrationOn) { a3=All.Time*All.Time*All.Time; a3inv=1.e0/a3; hubble_param = All.HubbleParam; hubble_param2 = hubble_param*hubble_param; } else a3 = a3inv = hubble_param = hubble_param2 =1.0; //MPI_Barrier(MPI_COMM_WORLD); particle_check(a3, a3inv, hubble_param, hubble_param2); 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 */ domain_Decomposition(); /* do domain decomposition if needed */ N_sinks = 0; for(i = 0; i < NumPart; i++) { if(P[i].Type == 5) N_sinks++; } compute_accelerations(0); /* compute accelerations for * the particles that are to be advanced */ /* 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; } /*SINKS*/ MPI_Barrier(MPI_COMM_WORLD); //MPI_Allreduce(&prad_avg, &prad_tot, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); //MPI_Allreduce(&pres_avg, &pres_tot, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); if(All.NumCurrentTiStep % 1000 == 0) printf("myrank = %d, Ngas = %d, NumPart = %d, TNgas = %lu, TNumPart = %lu, All.t_s = %lg, All.t_s0 = %lg, All.t_s0_sink = %lg, All.t_s0_acc = %lg\n", ThisTask, N_gas, NumPart, All.TotN_gas, All.TotNumPart, All.t_s, All.t_s0, All.t_s0_sink, All.t_s0_acc); MPI_Barrier(MPI_COMM_WORLD); tstart = second(); if(ThisTask == 0 && All.NumCurrentTiStep % 10000 == 0) printf("line 144 of run.c - before sink()\n"); if(/*All.t_s - All.t_s0_sink > 1.e5 || ray.r_min < 1.01*2.0e0*All.SofteningGas ||*/ All.flag_sink == 1 || (All.NumCurrentTiStep % 20 == 0 && All.NumCurrentTiStep > 0) || All.NumCurrentTiStep == 2) { sink(); } for(i = 0; i < N_gas; i++) if(SphP[i].sink > 0.5 && All.NumCurrentTiStep % 10000 == 0) printf("sinkval = %g \n", SphP[i].sink); if(ThisTask == 0 && All.NumCurrentTiStep % 10000 == 0) printf("line 144 of run.c - after sink()\n"); if(/*All.t_s - All.t_s0_sink > 1.e5 || ray.r_min < 1.01*2.0e0*All.SofteningGas ||*/ All.flag_sink == 1 || (All.NumCurrentTiStep % 20 == 0 && All.NumCurrentTiStep > 0) || All.NumCurrentTiStep == 2) { All.t_s0_sink = All.t_s; accrete(); } for(i = 0; i < N_gas; i++) if(SphP[i].sink > 0.5 && All.NumCurrentTiStep % 10000 == 0) printf("new new sinkval = %g \n", SphP[i].sink); tend = second(); All.CPU_Sinks += timediff(tstart,tend); MPI_Barrier(MPI_COMM_WORLD); // if(nsinks) // { All.NumForcesSinceLastDomainDecomp = All.TotNumPart * All.TreeDomainUpdateFrequency + 1; // } /*SINKS*/ advance_and_find_timesteps(); /* 'kick' active particles in * momentum space and compute new * timesteps for them */ #ifdef TURBULENCE if(N_gas>0) { tstart = second(); rsk_turbdriving(); tend = second(); All.CPU_Turbulence+= timediff(tstart,tend); } #endif 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(); system(All.ResubmitCommand); } 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; if(ThisTask == 0) printf("writing restart files!\n"); } t1 = second(); All.CPU_Total += timediff(t0, t1); CPUThisRun += timediff(t0, t1); } 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) */ }
/*! 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; int stopflag = 0; char stopfname[200], contfname[200]; double t0, t1; sprintf(stopfname, "%sstop", All.OutputDir); sprintf(contfname, "%scont", All.OutputDir); unlink(contfname); do /* main loop */ { t0 = second(); 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 */ domain_Decomposition(); /* do domain decomposition if needed */ compute_accelerations(0); /* compute accelerations for * the particles that are to be advanced */ /* 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 */ 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(); system(All.ResubmitCommand); } 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; } t1 = second(); All.CPU_Total += timediff(t0, t1); CPUThisRun += timediff(t0, t1); } 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) */ }