12#include "gadgetconfig.h"
20#include "../data/allvars.h"
21#include "../data/dtypes.h"
22#include "../data/mymalloc.h"
23#include "../logs/logs.h"
24#include "../main/simulation.h"
25#include "../mpi_utils/mpi_utils.h"
26#include "../system/system.h"
27#include "../time_integration/timestep.h"
48 if(!(
FdCPU = fopen(buf, mode)))
49 Terminate(
"error in opening file '%s'\n", buf);
53 Terminate(
"error in opening file '%s'\n", buf);
56 if(!(
FdInfo = fopen(buf, mode)))
57 Terminate(
"error in opening file '%s'\n", buf);
61 Terminate(
"error in opening file '%s'\n", buf);
65 Terminate(
"error in opening file '%s'\n", buf);
69 Terminate(
"error in opening file '%s'\n", buf);
72 if(!(
FdHydro = fopen(buf, mode)))
73 Terminate(
"error in opening file '%s'\n", buf);
77 Terminate(
"error in opening file '%s'\n", buf);
81 Terminate(
"error in opening file '%s'\n", buf);
85 Terminate(
"error in opening file '%s'\n", buf);
87#ifdef MEASURE_TOTAL_MOMENTUM
89 if(!(FdMomentum = fopen(buf, mode)))
90 Terminate(
"error in opening file '%s'\n", buf);
95 if(!(FdForceTest = fopen(buf, mode)))
96 Terminate(
"error in opening file '%s'\n", buf);
103 if(!(FdDebug = fopen(buf, mode)))
104 Terminate(
"error in opening file '%s'\n", buf);
109 fprintf(
FdCPUCSV,
"STEP, TIME, CPUS, MULTIPLEDOMAIN, HIGHESTTIMEBIN, ");
111 for(
int i = 0; i < CPU_LAST; i++)
124 if(!(FdSfr = fopen(buf, mode)))
125 Terminate(
"error in opening file '%s'\n", buf);
189 double z = 1.0 / (
All.
Time) - 1;
190 fprintf(
FdInfo,
"\nSync-Point %d, Time: %g, Redshift: %g, Systemstep: %g, Dloga: %g, Nsync-grv: %10llu, Nsync-hyd: %10llu\n",
193 printf(
"\n\nSync-Point %d, Time: %g, Redshift: %g, Systemstep: %g, Dloga: %g, Nsync-grv: %10llu, Nsync-hyd: %10llu\n",
202 fprintf(
FdInfo,
"\nSync-Point %d, Time: %g, Systemstep: %g, Nsync-grv: %10llu, Nsync-hyd: %10llu\n",
All.
NumCurrentTiStep,
211 tot_cumulative_grav[0] = tot_count_grav[0];
212 tot_cumulative_sph[0] = tot_count_sph[0];
216 tot_cumulative_grav[i] = tot_count_grav[i] + tot_cumulative_grav[i - 1];
217 tot_cumulative_sph[i] = tot_count_sph[i] + tot_cumulative_sph[i - 1];
231 avg_CPU_TimeBin[i] = 0;
243 corr_weight = weight / 2;
245 corr_weight = weight;
247 frac_CPU_TimeBin[i] = corr_weight * avg_CPU_TimeBin[i];
248 sum += frac_CPU_TimeBin[i];
254 frac_CPU_TimeBin[i] /= sum;
258 "Occupied timebins: gravity sph dt cumul-grav cumul-sph A D avg-time cpu-frac\n");
260 long long tot_grav = 0, tot_sph = 0;
261 for(
int i =
TIMEBINS - 1; i >= 0; i--)
262 if(tot_count_sph[i] > 0 || tot_count_grav[i] > 0)
265 FdTimebin,
" %c bin=%2d %10llu %10llu %16.12f %10llu %10llu %c %c %10.2f %5.1f%%\n",
270 avg_CPU_TimeBin[i], 100.0 * frac_CPU_TimeBin[i]);
274 tot_grav += tot_count_grav[i];
275 tot_sph += tot_count_sph[i];
278 fprintf(
FdTimebin,
" ------------------------\n");
279#if defined(PMGRID) && !defined(TREEPM_NOTIMESPLIT)
282 fprintf(
FdTimebin,
"PM-Step. Total: %10llu %10llu\n", tot_grav, tot_sph);
287 fprintf(
FdTimebin,
"Total active: %10llu %10llu\n", tot_grav, tot_sph);
300 for(
int i = 0; i < CPU_LAST; i++)
308 for(
int i = 0; i < CPU_LAST; i++)
334 double local_total = 0;
335 for(
int i = 0; i < CPU_LAST; i++)
338 double max_total = 0;
339 MPI_Reduce(&local_total, &max_total, 1, MPI_DOUBLE, MPI_MAX, 0,
Communicator);
341 double max_CPU_Step[CPU_LAST], avg_CPU_Step[CPU_LAST];
347 double summed_CPU_Step[CPU_LAST];
350 for(
int i = 0; i < CPU_LAST; i++)
351 summed_CPU_Step[i] = avg_CPU_Step[i];
353 for(
int i = CPU_LAST - 1; i > CPU_ALL; i--)
358 double avg_total = 0;
359 for(
int i = 0; i < CPU_LAST; i++)
361 avg_CPU_Step[i] /=
NTask;
362 avg_total += avg_CPU_Step[i];
364 summed_CPU_Step[i] /=
NTask;
365 CPU_Sum[i] += summed_CPU_Step[i];
370 put_symbol(cpu_String, 0., 1.0,
'-');
373 for(
int i = 1; i < CPU_LAST; i++)
378 double t1 = tsum + avg_CPU_Step[i] * (avg_CPU_Step[i] / max_CPU_Step[i]);
379 put_symbol(cpu_String, t0 / avg_total, t1 / avg_total,
Timer_data[i].symb);
383 t1 = tsum + avg_CPU_Step[i] * ((max_CPU_Step[i] - avg_CPU_Step[i]) / max_CPU_Step[i]);
384 put_symbol(cpu_String, t0 / avg_total, t1 / avg_total,
Timer_data[i].symbImbal);
407 fprintf(
FdCPU,
" diff cumulative\n");
409 for(
int i = 0; i < CPU_LAST; i++)
412 Timer_data[i].longname, summed_CPU_Step[i], summed_CPU_Step[i] / summed_CPU_Step[CPU_ALL] * 100.,
CPU_Sum[i],
417 fprintf(
FdCPU,
"\n");
426 for(
int i = 0; i < CPU_LAST; i++)
442void logs::put_symbol(
char *
string,
double t0,
double t1,
char c)
462 double dt = t - WallclockTime;
507 compute_global_quantities_of_system();
511 fprintf(
FdEnergy,
"%14.8g %14.8g %14.8g %14.8g",
All.
Time, SysState.EnergyInt, SysState.EnergyPot, SysState.EnergyKin);
513 for(
int i = 0; i <
NTYPES; i++)
514 fprintf(
FdEnergy,
" %14.8g %14.8g %14.8g", SysState.EnergyIntComp[i], SysState.EnergyPotComp[i],
515 SysState.EnergyKinComp[i]);
517 for(
int i = 0; i <
NTYPES; i++)
518 fprintf(
FdEnergy,
" %14.8g", SysState.MassComp[i]);
529#ifdef MEASURE_TOTAL_MOMENTUM
532 double mom[3] = {0, 0, 0};
536 for(
int j = 0; j < 3; j++)
541 double momsum[3] = {0, 0, 0};
542 MPI_Reduce(mom, momsum, 3, MPI_DOUBLE, MPI_SUM, 0,
Communicator);
546 fprintf(FdMomentum,
"%14.8g %25.15g %25.15g %25.15g\n",
All.
Time, momsum[0], momsum[1], momsum[2]);
560void logs::compute_global_quantities_of_system(
void)
570 for(
int n = 0; n <
NTYPES; n++)
572 sys.MassComp[n] = sys.EnergyKinComp[n] = sys.EnergyPotComp[n] = sys.EnergyIntComp[n] = 0;
574 for(
int j = 0; j < 4; j++)
575 sys.CenterOfMassComp[n][j] = sys.MomentumComp[n][j] = sys.AngMomentumComp[n][j] = 0;
582#if defined(SELFGRAVITY) && defined(EVALPOTENTIAL)
586#if defined(EXTERNALGRAVITY) && defined(EVALPOTENTIAL)
587 sys.EnergyPotComp[P[i].
getType()] += P[i].
getMass() * P[i].ExtPotential;
590 double vel[3] = {0, 0, 0};
592 if(P[i].getType() == 0)
594 for(
int j = 0; j < 3; j++)
595 vel[j] = P[i].Vel[j];
597 sys.EnergyKinComp[0] += 0.5 *
Sp->
P[i].
getMass() * (vel[0] * vel[0] + vel[1] * vel[1] + vel[2] * vel[2]);
601 sys.EnergyIntComp[0] +=
Sp->
P[i].
getMass() * egyspec;
606 for(
int j = 0; j < 3; j++)
607 vel[j] = P[i].Vel[j];
609 sys.EnergyKinComp[P[i].
getType()] +=
617 for(
int j = 0; j < 3; j++)
623 sys.AngMomentumComp[P[i].
getType()][0] +=
Sp->
P[i].
getMass() * (pos[1] * vel[2] - pos[2] * vel[1]);
624 sys.AngMomentumComp[P[i].
getType()][1] +=
Sp->
P[i].
getMass() * (pos[2] * vel[0] - pos[0] * vel[2]);
625 sys.AngMomentumComp[P[i].
getType()][2] +=
Sp->
P[i].
getMass() * (pos[0] * vel[1] - pos[1] * vel[0]);
629 MPI_Reduce(&sys.MassComp[0], &SysState.MassComp[0],
NTYPES, MPI_DOUBLE, MPI_SUM, 0,
Communicator);
630 MPI_Reduce(&sys.EnergyPotComp[0], &SysState.EnergyPotComp[0],
NTYPES, MPI_DOUBLE, MPI_SUM, 0,
Communicator);
631 MPI_Reduce(&sys.EnergyIntComp[0], &SysState.EnergyIntComp[0],
NTYPES, MPI_DOUBLE, MPI_SUM, 0,
Communicator);
632 MPI_Reduce(&sys.EnergyKinComp[0], &SysState.EnergyKinComp[0],
NTYPES, MPI_DOUBLE, MPI_SUM, 0,
Communicator);
633 MPI_Reduce(&sys.MomentumComp[0][0], &SysState.MomentumComp[0][0],
NTYPES * 4, MPI_DOUBLE, MPI_SUM, 0,
Communicator);
634 MPI_Reduce(&sys.AngMomentumComp[0][0], &SysState.AngMomentumComp[0][0],
NTYPES * 4, MPI_DOUBLE, MPI_SUM, 0,
Communicator);
635 MPI_Reduce(&sys.CenterOfMassComp[0][0], &SysState.CenterOfMassComp[0][0],
NTYPES * 4, MPI_DOUBLE, MPI_SUM, 0,
Communicator);
639 for(
int i = 0; i <
NTYPES; i++)
640 SysState.EnergyTotComp[i] = SysState.EnergyKinComp[i] + SysState.EnergyPotComp[i] + SysState.EnergyIntComp[i];
642 SysState.Mass = SysState.EnergyKin = SysState.EnergyPot = SysState.EnergyInt = SysState.EnergyTot = 0;
644 for(
int j = 0; j < 3; j++)
645 SysState.Momentum[j] = SysState.AngMomentum[j] = SysState.CenterOfMass[j] = 0;
647 for(
int i = 0; i <
NTYPES; i++)
649 SysState.Mass += SysState.MassComp[i];
650 SysState.EnergyKin += SysState.EnergyKinComp[i];
651 SysState.EnergyPot += SysState.EnergyPotComp[i];
652 SysState.EnergyInt += SysState.EnergyIntComp[i];
653 SysState.EnergyTot += SysState.EnergyTotComp[i];
655 for(
int j = 0; j < 3; j++)
657 SysState.Momentum[j] += SysState.MomentumComp[i][j];
658 SysState.AngMomentum[j] += SysState.AngMomentumComp[i][j];
659 SysState.CenterOfMass[j] += SysState.CenterOfMassComp[i][j];
663 for(
int i = 0; i <
NTYPES; i++)
664 for(
int j = 0; j < 3; j++)
665 if(SysState.MassComp[i] > 0)
666 SysState.CenterOfMassComp[i][j] /= SysState.MassComp[i];
668 for(
int j = 0; j < 3; j++)
669 if(SysState.Mass > 0)
670 SysState.CenterOfMass[j] /= SysState.Mass;
672 for(
int i = 0; i <
NTYPES; i++)
674 SysState.CenterOfMassComp[i][3] = SysState.MomentumComp[i][3] = SysState.AngMomentumComp[i][3] = 0;
675 for(
int j = 0; j < 3; j++)
677 SysState.CenterOfMassComp[i][3] += SysState.CenterOfMassComp[i][j] * SysState.CenterOfMassComp[i][j];
678 SysState.MomentumComp[i][3] += SysState.MomentumComp[i][j] * SysState.MomentumComp[i][j];
679 SysState.AngMomentumComp[i][3] += SysState.AngMomentumComp[i][j] * SysState.AngMomentumComp[i][j];
681 SysState.CenterOfMassComp[i][3] =
sqrt(SysState.CenterOfMassComp[i][3]);
682 SysState.MomentumComp[i][3] =
sqrt(SysState.MomentumComp[i][3]);
683 SysState.AngMomentumComp[i][3] =
sqrt(SysState.AngMomentumComp[i][3]);
686 SysState.CenterOfMass[3] = SysState.Momentum[3] = SysState.AngMomentum[3] = 0;
688 for(
int j = 0; j < 3; j++)
690 SysState.CenterOfMass[3] += SysState.CenterOfMass[j] * SysState.CenterOfMass[j];
691 SysState.Momentum[3] += SysState.Momentum[j] * SysState.Momentum[j];
692 SysState.AngMomentum[3] += SysState.AngMomentum[j] * SysState.AngMomentum[j];
695 SysState.CenterOfMass[3] =
sqrt(SysState.CenterOfMass[3]);
696 SysState.Momentum[3] =
sqrt(SysState.Momentum[3]);
697 SysState.AngMomentum[3] =
sqrt(SysState.AngMomentum[3]);
701 MPI_Bcast(&SysState,
sizeof(state_of_system), MPI_BYTE, 0,
Communicator);
global_data_all_processes All
void intpos_to_pos(MyIntPosType *intpos, T *posdiff)
int flush_everything(void)
void init_cpu_log(simparticles *Sp_ptr)
timer_d Timer_data[CPU_LAST+1]
void write_cpu_log(void)
Write the FdBalance and FdCPU files.
void open_logfiles(void)
Open files for logging.
double CPU_Step[CPU_LAST]
double measure_time(void)
void output_log_messages(void)
Write the FdInfo and FdTimeBin files.
double timediff(double t0, double t1)
void compute_statistics(void)
Computes new global statistics if needed (done by energy_statistics())
enum timers TimerStack[TIMER_STACK_DEPTH]
void compute_total_momentum(void)
void report_detailed_memory_usage_of_largest_task(void)
Output memory usage for the task with the greatest amount of memory allocated.
void mpi_printf(const char *fmt,...)
double get_utherm_from_entropy(int i)
TimeBinData TimeBinsGravity
TimeBinData TimeBinsHydro
int TimeBinSynchronized[TIMEBINS]
#define NUMBER_OF_MEASUREMENTS_TO_RECORD
#define MAXLEN_PATH_EXTRA
#define TIMER_START(counter)
Starts the timer counter.
#define TIMER_STOP(counter)
Stops the timer counter.
void sumup_large_ints(int n, int *src, long long *res, MPI_Comm comm)
int TimeBinCount[TIMEBINS]
long long GlobalNSynchronizedHydro
long long GlobalNSynchronizedGravity
double CPU_TimeBinMeasurements[TIMEBINS][NUMBER_OF_MEASUREMENTS_TO_RECORD]
enum restart_options RestartFlag
int CPU_TimeBinCountMeasurements[TIMEBINS]
int ComovingIntegrationOn
int SmallestTimeBinWithDomainDecomposition
char OutputDir[MAXLEN_PATH]
double TimeLastStatistics
void set_cosmo_factors_for_current_time(void)
int HighestOccupiedTimeBin
unsigned char getType(void)
void myflush(FILE *fstream)