GADGET-4
logs.cc
Go to the documentation of this file.
1/*******************************************************************************
2 * \copyright This file is part of the GADGET4 N-body/SPH code developed
3 * \copyright by Volker Springel. Copyright (C) 2014-2020 by Volker Springel
4 * \copyright (vspringel@mpa-garching.mpg.de) and all contributing authors.
5 *******************************************************************************/
6
12#include "gadgetconfig.h"
13
14#include <math.h>
15#include <mpi.h>
16#include <stdio.h>
17#include <stdlib.h>
18#include <string.h>
19
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"
28
36{
37 char mode[2], buf[MAXLEN_PATH_EXTRA];
38
40 strcpy(mode, "w");
41 else
42 strcpy(mode, "a");
43
44 if(ThisTask != 0) /* only the root processors writes to the log files */
45 return;
46
47 sprintf(buf, "%s%s", All.OutputDir, "cpu.txt");
48 if(!(FdCPU = fopen(buf, mode)))
49 Terminate("error in opening file '%s'\n", buf);
50
51 sprintf(buf, "%s%s", All.OutputDir, "cpu.csv");
52 if(!(FdCPUCSV = fopen(buf, mode)))
53 Terminate("error in opening file '%s'\n", buf);
54
55 sprintf(buf, "%s%s", All.OutputDir, "info.txt");
56 if(!(FdInfo = fopen(buf, mode)))
57 Terminate("error in opening file '%s'\n", buf);
58
59 sprintf(buf, "%s%s", All.OutputDir, "energy.txt");
60 if(!(FdEnergy = fopen(buf, mode)))
61 Terminate("error in opening file '%s'\n", buf);
62
63 sprintf(buf, "%s%s", All.OutputDir, "timings.txt");
64 if(!(FdTimings = fopen(buf, mode)))
65 Terminate("error in opening file '%s'\n", buf);
66
67 sprintf(buf, "%s%s", All.OutputDir, "density.txt");
68 if(!(FdDensity = fopen(buf, mode)))
69 Terminate("error in opening file '%s'\n", buf);
70
71 sprintf(buf, "%s%s", All.OutputDir, "hydro.txt");
72 if(!(FdHydro = fopen(buf, mode)))
73 Terminate("error in opening file '%s'\n", buf);
74
75 sprintf(buf, "%s%s", All.OutputDir, "balance.txt");
76 if(!(FdBalance = fopen(buf, mode)))
77 Terminate("error in opening file '%s'\n", buf);
78
79 sprintf(buf, "%s%s", All.OutputDir, "timebins.txt");
80 if(!(FdTimebin = fopen(buf, mode)))
81 Terminate("error in opening file '%s'\n", buf);
82
83 sprintf(buf, "%s%s", All.OutputDir, "domain.txt");
84 if(!(FdDomain = fopen(buf, mode)))
85 Terminate("error in opening file '%s'\n", buf);
86
87#ifdef MEASURE_TOTAL_MOMENTUM
88 sprintf(buf, "%s%s", All.OutputDir, "momentum.txt");
89 if(!(FdMomentum = fopen(buf, mode)))
90 Terminate("error in opening file '%s'\n", buf);
91#endif
92
93#ifdef FORCETEST
94 sprintf(buf, "%s%s", All.OutputDir, "forcetest.txt");
95 if(!(FdForceTest = fopen(buf, mode)))
96 Terminate("error in opening file '%s'\n", buf);
97
98 fclose(FdForceTest);
99#endif
100
101#ifdef DEBUG_MD5
102 sprintf(buf, "%s%s", All.OutputDir, "debug_md5.txt");
103 if(!(FdDebug = fopen(buf, mode)))
104 Terminate("error in opening file '%s'\n", buf);
105#endif
106
107 fprintf(FdBalance, "\n");
108
109 fprintf(FdCPUCSV, "STEP, TIME, CPUS, MULTIPLEDOMAIN, HIGHESTTIMEBIN, ");
110
111 for(int i = 0; i < CPU_LAST; i++)
112 {
113 if(Timer_data[i].symb != 0 && Timer_data[i].symbImbal != 0)
114 fprintf(FdBalance, "%-20s = '%c' / '%c'\n", Timer_data[i].longname, Timer_data[i].symb, Timer_data[i].symbImbal);
115
116 fprintf(FdCPUCSV, "%s1, %s2, %s3, ", Timer_data[i].shortname, Timer_data[i].shortname, Timer_data[i].shortname);
117 }
118 fprintf(FdBalance, "\n");
119
120 fprintf(FdCPUCSV, "\n");
121
122#ifdef STARFORMATION
123 sprintf(buf, "%s%s", All.OutputDir, "sfr.txt");
124 if(!(FdSfr = fopen(buf, mode)))
125 Terminate("error in opening file '%s'\n", buf);
126#endif
127}
128
130{
131#ifndef REDUCE_FLUSH
132 return 0;
133#else
134 if(ThisTask == 0)
135 {
136 if((CPUThisRun - All.FlushLast) < All.FlushCpuTimeDiff)
137 {
138 return 0;
139 }
140 else
141 {
142 All.FlushLast = CPUThisRun;
143 }
144 }
145 else
146 {
147 return 0;
148 }
149#endif
150
151 mpi_printf("Flushing...\n");
152
153 fflush(FdDomain);
154 fflush(FdTimings);
155 fflush(FdInfo);
156 fflush(FdTimebin);
157 fflush(FdBalance);
158 fflush(FdCPU);
159 fflush(FdEnergy);
160 fflush(FdCPUCSV);
161
162#ifdef STARFORMATION
163 fflush(FdSfr);
164#endif
165
166 return 1;
167}
168
176{
177 TIMER_START(CPU_LOGS);
178
179 long long tot_count_grav[TIMEBINS], tot_count_sph[TIMEBINS];
182
184
185 if(ThisTask == 0)
186 {
188 {
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",
196 fprintf(FdTimebin, "\nSync-Point %d, Time: %g, Redshift: %g, Systemstep: %g, Dloga: %g\n", All.NumCurrentTiStep, All.Time, z,
199 }
200 else
201 {
202 fprintf(FdInfo, "\nSync-Point %d, Time: %g, Systemstep: %g, Nsync-grv: %10llu, Nsync-hyd: %10llu\n", All.NumCurrentTiStep,
204 printf("\n\nSync-Point %d, Time: %g, Systemstep: %g, Nsync-grv: %10llu, Nsync-hyd: %10llu\n", All.NumCurrentTiStep, All.Time,
206 fprintf(FdTimebin, "\nSync-Point %d, Time: %g, Systemstep: %g\n", All.NumCurrentTiStep, All.Time, All.TimeStep);
208 }
209
210 long long tot_cumulative_grav[TIMEBINS], tot_cumulative_sph[TIMEBINS];
211 tot_cumulative_grav[0] = tot_count_grav[0];
212 tot_cumulative_sph[0] = tot_count_sph[0];
213
214 for(int i = 1; i < TIMEBINS; i++)
215 {
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];
218 }
219
220 double avg_CPU_TimeBin[TIMEBINS];
221
222 for(int i = 0; i < TIMEBINS; i++)
223 {
224 double sum = 0;
225 for(int j = 0; j < All.CPU_TimeBinCountMeasurements[i]; j++)
226 sum += All.CPU_TimeBinMeasurements[i][j];
227
229 avg_CPU_TimeBin[i] = sum / All.CPU_TimeBinCountMeasurements[i];
230 else
231 avg_CPU_TimeBin[i] = 0;
232 }
233
234 int weight = 1;
235 double sum = 0;
236 double frac_CPU_TimeBin[TIMEBINS];
237
238 for(int i = All.HighestOccupiedTimeBin; i >= 0 && tot_count_grav[i] > 0; i--, weight *= 2)
239 {
240 int corr_weight;
241
242 if(weight > 1)
243 corr_weight = weight / 2;
244 else
245 corr_weight = weight;
246
247 frac_CPU_TimeBin[i] = corr_weight * avg_CPU_TimeBin[i];
248 sum += frac_CPU_TimeBin[i];
249 }
250
251 for(int i = All.HighestOccupiedTimeBin; i >= 0 && tot_count_grav[i] > 0; i--)
252 {
253 if(sum)
254 frac_CPU_TimeBin[i] /= sum;
255 }
256
257 fprintf(FdTimebin,
258 "Occupied timebins: gravity sph dt cumul-grav cumul-sph A D avg-time cpu-frac\n");
259
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)
263 {
264 fprintf(
265 FdTimebin, " %c bin=%2d %10llu %10llu %16.12f %10llu %10llu %c %c %10.2f %5.1f%%\n",
266 Sp->TimeBinSynchronized[i] ? 'X' : ' ', i, tot_count_grav[i], tot_count_sph[i],
267 i > 0 ? (((integertime)1) << i) * All.Timebase_interval : 0.0, tot_cumulative_grav[i], tot_cumulative_sph[i],
268 (i == All.HighestActiveTimeBin) ? '<' : ' ',
270 avg_CPU_TimeBin[i], 100.0 * frac_CPU_TimeBin[i]);
271
272 if(Sp->TimeBinSynchronized[i])
273 {
274 tot_grav += tot_count_grav[i];
275 tot_sph += tot_count_sph[i];
276 }
277 }
278 fprintf(FdTimebin, " ------------------------\n");
279#if defined(PMGRID) && !defined(TREEPM_NOTIMESPLIT)
280 if(All.PM_Ti_endstep == All.Ti_Current)
281 {
282 fprintf(FdTimebin, "PM-Step. Total: %10llu %10llu\n", tot_grav, tot_sph);
283 }
284 else
285#endif
286 {
287 fprintf(FdTimebin, "Total active: %10llu %10llu\n", tot_grav, tot_sph);
288 }
289 fprintf(FdTimebin, "\n");
291 }
292
293 TIMER_STOP(CPU_LOGS);
294}
295
297{
298 Sp = Sp_ptr;
299
300 for(int i = 0; i < CPU_LAST; i++)
301 {
302 if(Timer_data[i].parent >= 0)
304 else
305 Timer_data[i].depth = 0;
306 }
307
308 for(int i = 0; i < CPU_LAST; i++)
309 {
310 CPU_Sum[i] = 0.;
311 CPU_Step[i] = 0.;
312 }
313 CPUThisRun = 0.;
314
315 TimerStackPos = 0;
316 TimerStack[0] = CPU_MISC;
317
318 WallclockTime = Logs.second();
319 StartOfRun = Logs.second();
320}
321
331{
332 TIMER_START(CPU_LOGS);
333
334 double local_total = 0;
335 for(int i = 0; i < CPU_LAST; i++)
336 local_total += CPU_Step[i];
337
338 double max_total = 0;
339 MPI_Reduce(&local_total, &max_total, 1, MPI_DOUBLE, MPI_MAX, 0, Communicator);
340
341 double max_CPU_Step[CPU_LAST], avg_CPU_Step[CPU_LAST];
342 MPI_Reduce(CPU_Step, max_CPU_Step, CPU_LAST, MPI_DOUBLE, MPI_MAX, 0, Communicator);
343 MPI_Reduce(CPU_Step, avg_CPU_Step, CPU_LAST, MPI_DOUBLE, MPI_SUM, 0, Communicator);
344
345 if(ThisTask == 0)
346 {
347 double summed_CPU_Step[CPU_LAST];
348
349 /* sum up cpu items into groups */
350 for(int i = 0; i < CPU_LAST; i++)
351 summed_CPU_Step[i] = avg_CPU_Step[i];
352
353 for(int i = CPU_LAST - 1; i > CPU_ALL; i--)
354 if(Timer_data[i].parent >= 0)
355 summed_CPU_Step[Timer_data[i].parent] += summed_CPU_Step[i];
356
357 /* calc averages, update CPU_Sum */
358 double avg_total = 0;
359 for(int i = 0; i < CPU_LAST; i++)
360 {
361 avg_CPU_Step[i] /= NTask;
362 avg_total += avg_CPU_Step[i];
363
364 summed_CPU_Step[i] /= NTask;
365 CPU_Sum[i] += summed_CPU_Step[i];
366 }
367
368 /* create balance.txt string */
369 char cpu_String[CPU_STRING_LEN + 1];
370 put_symbol(cpu_String, 0., 1.0, '-');
371
372 double tsum = 0.0;
373 for(int i = 1; i < CPU_LAST; i++)
374 {
375 if(max_CPU_Step[i] > 0 && Timer_data[i].symb != 0 && Timer_data[i].symbImbal != 0)
376 {
377 double t0 = tsum;
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);
380 tsum += t1 - t0;
381
382 t0 = tsum;
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);
385 tsum += t1 - t0;
386 }
387 }
388
389 // put_symbol(cpu_String, tsum / max_total, 1.0, '-');
390 fprintf(FdBalance, "Step=%7d sec=%10.3f Nsync-grv=%10llu Nsync-hyd=%10llu %s\n", All.NumCurrentTiStep, max_total,
393
395 {
398 (NUMBER_OF_MEASUREMENTS_TO_RECORD - 1) * sizeof(double));
399 }
400
402
403 fprintf(FdCPUCSV, "%d, %g, %d, %d, ", All.NumCurrentTiStep, All.Time, NTask, All.HighestActiveTimeBin);
404
405 fprintf(FdCPU, "Step %d, Time: %g, CPUs: %d, HighestActiveTimeBin: %d\n", All.NumCurrentTiStep, All.Time, NTask,
407 fprintf(FdCPU, " diff cumulative\n");
408
409 for(int i = 0; i < CPU_LAST; i++)
410 {
411 fprintf(FdCPU, "%*s%*s%10.2f %5.1f%% %10.2f %5.1f%%\n", 2 * Timer_data[i].depth, "", -20 + 2 * Timer_data[i].depth,
412 Timer_data[i].longname, summed_CPU_Step[i], summed_CPU_Step[i] / summed_CPU_Step[CPU_ALL] * 100., CPU_Sum[i],
413 CPU_Sum[i] / CPU_Sum[CPU_ALL] * 100.);
414 fprintf(FdCPUCSV, "%f, %f, %f, ", summed_CPU_Step[i], CPU_Sum[i], CPU_Sum[i] / CPU_Sum[CPU_ALL] * 100.);
415 }
416
417 fprintf(FdCPU, "\n");
418 myflush(FdCPU);
419
420 fprintf(FdCPUCSV, "\n");
422 }
423
424 CPUThisRun = Logs.timediff(StartOfRun, Logs.second());
425
426 for(int i = 0; i < CPU_LAST; i++)
427 CPU_Step[i] = 0.;
428
429 TIMER_STOP(CPU_LOGS);
430}
431
442void logs::put_symbol(char *string, double t0, double t1, char c)
443{
444 int i = (int)(t0 * CPU_STRING_LEN + 0.5);
445 int j = (int)(t1 * CPU_STRING_LEN);
446
447 if(i < 0)
448 i = 0;
449 if(j >= CPU_STRING_LEN)
450 j = CPU_STRING_LEN;
451
452 while(i <= j)
453 string[i++] = c;
454
455 string[CPU_STRING_LEN] = 0;
456}
457
458double logs::measure_time(void) /* strategy: call this at end of functions to account for time in this function, and before another
459 (nontrivial) function is called */
460{
461 double t = Logs.second();
462 double dt = t - WallclockTime;
463 WallclockTime = t;
464
465 return dt;
466}
467
468/* returns the number of cpu-ticks in seconds that
469 * have elapsed. (or the wall-clock time)
470 */
471double logs::second(void)
472{
473 return MPI_Wtime();
474
475 /*
476 * possible alternative:
477 *
478 * return ((double) clock()) / CLOCKS_PER_SEC;
479 *
480 * but note: on AIX and presumably many other 32bit systems,
481 * clock() has only a resolution of 10ms=0.01sec
482 */
483}
484
485/* returns the time difference between two measurements
486 * obtained with Logs.second().
487 */
488double logs::timediff(double t0, double t1)
489{
490 double dt = t1 - t0;
491
492 if(dt < 0)
493 dt = 0;
494
495 return dt;
496}
497
502{
503 /* check whether we want a full energy statistics */
505 All.HighestActiveTimeBin == All.HighestOccupiedTimeBin) /* allow only top-level synchronization points */
506 {
507 compute_global_quantities_of_system();
508
509 if(ThisTask == 0)
510 {
511 fprintf(FdEnergy, "%14.8g %14.8g %14.8g %14.8g", All.Time, SysState.EnergyInt, SysState.EnergyPot, SysState.EnergyKin);
512
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]);
516
517 for(int i = 0; i < NTYPES; i++)
518 fprintf(FdEnergy, " %14.8g", SysState.MassComp[i]);
519
520 fprintf(FdEnergy, "\n");
521
523 }
524
526 }
527}
528
529#ifdef MEASURE_TOTAL_MOMENTUM
531{
532 double mom[3] = {0, 0, 0};
533
534 for(int i = 0; i < Sp->NumPart; i++)
535 {
536 for(int j = 0; j < 3; j++)
537 mom[j] += Sp->P[i].getMass() * Sp->P[i].Vel[j];
538 }
539
540 // some the stuff over all processors
541 double momsum[3] = {0, 0, 0};
542 MPI_Reduce(mom, momsum, 3, MPI_DOUBLE, MPI_SUM, 0, Communicator);
543
544 if(ThisTask == 0)
545 {
546 fprintf(FdMomentum, "%14.8g %25.15g %25.15g %25.15g\n", All.Time, momsum[0], momsum[1], momsum[2]);
547
548 myflush(FdMomentum);
549 }
550}
551#endif
552
560void logs::compute_global_quantities_of_system(void)
561{
562 state_of_system sys;
563 double egyspec;
564
565 particle_data *P = Sp->P;
566 // sph_particle_data *SphP = Sp->SphP;
567
569
570 for(int n = 0; n < NTYPES; n++)
571 {
572 sys.MassComp[n] = sys.EnergyKinComp[n] = sys.EnergyPotComp[n] = sys.EnergyIntComp[n] = 0;
573
574 for(int j = 0; j < 4; j++)
575 sys.CenterOfMassComp[n][j] = sys.MomentumComp[n][j] = sys.AngMomentumComp[n][j] = 0;
576 }
577
578 for(int i = 0; i < Sp->NumPart; i++)
579 {
580 sys.MassComp[P[i].getType()] += Sp->P[i].getMass();
581
582#if defined(SELFGRAVITY) && defined(EVALPOTENTIAL)
583 sys.EnergyPotComp[P[i].getType()] += 0.5 * Sp->P[i].getMass() * P[i].Potential / All.cf_atime;
584#endif
585
586#if defined(EXTERNALGRAVITY) && defined(EVALPOTENTIAL)
587 sys.EnergyPotComp[P[i].getType()] += P[i].getMass() * P[i].ExtPotential;
588#endif
589
590 double vel[3] = {0, 0, 0};
591
592 if(P[i].getType() == 0)
593 {
594 for(int j = 0; j < 3; j++)
595 vel[j] = P[i].Vel[j];
596
597 sys.EnergyKinComp[0] += 0.5 * Sp->P[i].getMass() * (vel[0] * vel[0] + vel[1] * vel[1] + vel[2] * vel[2]);
598
599 egyspec = Sp->get_utherm_from_entropy(i);
600
601 sys.EnergyIntComp[0] += Sp->P[i].getMass() * egyspec;
602 }
603#if(NTYPES > 1)
604 else
605 {
606 for(int j = 0; j < 3; j++)
607 vel[j] = P[i].Vel[j];
608
609 sys.EnergyKinComp[P[i].getType()] +=
610 0.5 * Sp->P[i].getMass() * (vel[0] * vel[0] + vel[1] * vel[1] + vel[2] * vel[2]) * All.cf_a2inv;
611 }
612#endif
613
614 double pos[3];
615 Sp->intpos_to_pos(P[i].IntPos, pos); // converts the integer coordinates to floating point
616
617 for(int j = 0; j < 3; j++)
618 {
619 sys.MomentumComp[P[i].getType()][j] += Sp->P[i].getMass() * vel[j];
620 sys.CenterOfMassComp[P[i].getType()][j] += Sp->P[i].getMass() * pos[j];
621 }
622
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]);
626 }
627
628 // some the stuff over all processors
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);
636
637 if(ThisTask == 0)
638 {
639 for(int i = 0; i < NTYPES; i++)
640 SysState.EnergyTotComp[i] = SysState.EnergyKinComp[i] + SysState.EnergyPotComp[i] + SysState.EnergyIntComp[i];
641
642 SysState.Mass = SysState.EnergyKin = SysState.EnergyPot = SysState.EnergyInt = SysState.EnergyTot = 0;
643
644 for(int j = 0; j < 3; j++)
645 SysState.Momentum[j] = SysState.AngMomentum[j] = SysState.CenterOfMass[j] = 0;
646
647 for(int i = 0; i < NTYPES; i++)
648 {
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];
654
655 for(int j = 0; j < 3; j++)
656 {
657 SysState.Momentum[j] += SysState.MomentumComp[i][j];
658 SysState.AngMomentum[j] += SysState.AngMomentumComp[i][j];
659 SysState.CenterOfMass[j] += SysState.CenterOfMassComp[i][j];
660 }
661 }
662
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];
667
668 for(int j = 0; j < 3; j++)
669 if(SysState.Mass > 0)
670 SysState.CenterOfMass[j] /= SysState.Mass;
671
672 for(int i = 0; i < NTYPES; i++)
673 {
674 SysState.CenterOfMassComp[i][3] = SysState.MomentumComp[i][3] = SysState.AngMomentumComp[i][3] = 0;
675 for(int j = 0; j < 3; j++)
676 {
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];
680 }
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]);
684 }
685
686 SysState.CenterOfMass[3] = SysState.Momentum[3] = SysState.AngMomentum[3] = 0;
687
688 for(int j = 0; j < 3; j++)
689 {
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];
693 }
694
695 SysState.CenterOfMass[3] = sqrt(SysState.CenterOfMass[3]);
696 SysState.Momentum[3] = sqrt(SysState.Momentum[3]);
697 SysState.AngMomentum[3] = sqrt(SysState.AngMomentum[3]);
698 }
699
700 // give everyone the result, maybe the want to do something with it
701 MPI_Bcast(&SysState, sizeof(state_of_system), MPI_BYTE, 0, Communicator);
702}
global_data_all_processes All
Definition: main.cc:40
void intpos_to_pos(MyIntPosType *intpos, T *posdiff)
int flush_everything(void)
Definition: logs.cc:129
void init_cpu_log(simparticles *Sp_ptr)
Definition: logs.cc:296
timer_d Timer_data[CPU_LAST+1]
Definition: logs.h:113
void write_cpu_log(void)
Write the FdBalance and FdCPU files.
Definition: logs.cc:330
double CPUThisRun
Definition: logs.h:43
FILE * FdHydro
Definition: logs.h:49
void open_logfiles(void)
Open files for logging.
Definition: logs.cc:35
double CPU_Step[CPU_LAST]
Definition: logs.h:115
simparticles * Sp
Definition: logs.h:41
double CPU_Sum[CPU_LAST]
Definition: logs.h:117
double measure_time(void)
Definition: logs.cc:458
FILE * FdEnergy
Definition: logs.h:46
FILE * FdTimebin
Definition: logs.h:51
void output_log_messages(void)
Write the FdInfo and FdTimeBin files.
Definition: logs.cc:175
double timediff(double t0, double t1)
Definition: logs.cc:488
int TimerStackPos
Definition: logs.h:120
FILE * FdTimings
Definition: logs.h:47
void compute_statistics(void)
Computes new global statistics if needed (done by energy_statistics())
Definition: logs.cc:501
enum timers TimerStack[TIMER_STACK_DEPTH]
Definition: logs.h:119
FILE * FdCPUCSV
Definition: logs.h:55
double second(void)
Definition: logs.cc:471
FILE * FdDomain
Definition: logs.h:52
FILE * FdCPU
Definition: logs.h:53
FILE * FdInfo
Definition: logs.h:45
void compute_total_momentum(void)
FILE * FdDensity
Definition: logs.h:48
FILE * FdBalance
Definition: logs.h:50
void report_detailed_memory_usage_of_largest_task(void)
Output memory usage for the task with the greatest amount of memory allocated.
Definition: mymalloc.cc:311
void mpi_printf(const char *fmt,...)
Definition: setcomm.h:55
int ThisTask
Definition: setcomm.h:33
int NTask
Definition: setcomm.h:32
MPI_Comm Communicator
Definition: setcomm.h:31
double get_utherm_from_entropy(int i)
Definition: simparticles.h:238
TimeBinData TimeBinsGravity
Definition: simparticles.h:205
particle_data * P
Definition: simparticles.h:54
TimeBinData TimeBinsHydro
Definition: simparticles.h:204
int TimeBinSynchronized[TIMEBINS]
Definition: simparticles.h:203
#define NUMBER_OF_MEASUREMENTS_TO_RECORD
Definition: constants.h:42
#define TIMEBINS
Definition: constants.h:332
#define MAXLEN_PATH_EXTRA
Definition: constants.h:301
#define NTYPES
Definition: constants.h:308
int integertime
Definition: constants.h:331
@ RST_BEGIN
Definition: dtypes.h:313
#define CPU_STRING_LEN
Definition: logs.h:20
logs Logs
Definition: main.cc:43
#define TIMER_START(counter)
Starts the timer counter.
Definition: logs.h:197
#define TIMER_STOP(counter)
Stops the timer counter.
Definition: logs.h:220
#define Terminate(...)
Definition: macros.h:15
void sumup_large_ints(int n, int *src, long long *res, MPI_Comm comm)
memory Mem
Definition: main.cc:44
expr log(half arg)
Definition: half.hpp:2745
expr sqrt(half arg)
Definition: half.hpp:2777
int TimeBinCount[TIMEBINS]
Definition: timestep.h:21
long long GlobalNSynchronizedHydro
Definition: allvars.h:90
long long GlobalNSynchronizedGravity
Definition: allvars.h:91
double CPU_TimeBinMeasurements[TIMEBINS][NUMBER_OF_MEASUREMENTS_TO_RECORD]
Definition: allvars.h:242
enum restart_options RestartFlag
Definition: allvars.h:68
int CPU_TimeBinCountMeasurements[TIMEBINS]
Definition: allvars.h:241
integertime Ti_Current
Definition: allvars.h:188
int SmallestTimeBinWithDomainDecomposition
Definition: allvars.h:160
char OutputDir[MAXLEN_PATH]
Definition: allvars.h:272
void set_cosmo_factors_for_current_time(void)
Definition: allvars.cc:20
int parent
Definition: logs.h:106
char depth
Definition: logs.h:111
MyDouble getMass(void)
MyFloat Vel[3]
Definition: particle_data.h:54
unsigned char getType(void)
void myflush(FILE *fstream)
Definition: system.cc:125