GADGET-4
restart.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 <gsl/gsl_rng.h>
15#include <math.h>
16#include <mpi.h>
17#include <stdio.h>
18#include <stdlib.h>
19#include <string.h>
20#include <sys/stat.h>
21
22#include "../data/allvars.h"
23#include "../data/dtypes.h"
24#include "../data/mymalloc.h"
25#include "../domain/domain.h"
26#include "../io/io.h"
27#include "../io/restart.h"
28#include "../lightcone/lightcone.h"
29#include "../logs/logs.h"
30#include "../logs/timer.h"
31#include "../main/simulation.h"
32#include "../mpi_utils/mpi_utils.h"
33#include "../ngbtree/ngbtree.h"
34#include "../system/system.h"
35#include "../time_integration/timestep.h"
36
37void restart::write(sim *Sim_ptr)
38{
39 Sim = Sim_ptr;
40 do_restart(MODUS_WRITE);
41}
42
50void restart::load(sim *Sim_ptr)
51{
52 Sim = Sim_ptr;
53 global_data_all_processes all = All; /* save global variables. (will be read from restart file) */
54
55 do_restart(MODUS_READ); /* ... read restart file. Note: This also resets
56 all variables in the struct `All'.
57 However, during the run, some variables in the parameter
58 file are allowed to be changed, if desired. These need to
59 copied in the way below.
60 */
61
62 /* now update those parameters that were changed in the parameterfile, and where a change is allowed */
63
64 for(int i = 0; i < All.NParameters; i++)
65 {
67 {
68 size_t off = (char *)All.ParametersValue[i] - (char *)&All;
69
70 if(off > sizeof(All))
71 Terminate("Invalid parameter pointer: '%s' i=%d off=%lld\n", All.ParametersTag[i], i, (long long)off);
72
73 switch(All.ParametersType[i])
74 {
75 case PARAM_DOUBLE:
76 {
77 double *old_dbl = (double *)((char *)&All + off);
78 double *new_dbl = (double *)((char *)&all + off);
79
80 if(*new_dbl != *old_dbl)
81 {
82 mpi_printf("RESTART: %s modified from %g to %g while restarting at Time=%g\n", All.ParametersTag[i], *old_dbl,
83 *new_dbl, All.Time);
84 *old_dbl = *new_dbl;
85 }
86 }
87 break;
88 case PARAM_STRING:
89 {
90 char *old_p = (char *)&All + off;
91 char *new_p = (char *)&all + off;
92 if(strncmp(new_p, old_p, MAXLEN_PARAM_VALUE))
93 {
94 mpi_printf("RESTART: %s modified from '%s' to '%s' while restarting at Time=%g\n", All.ParametersTag[i], old_p,
95 new_p, All.Time);
96 strncpy(old_p, new_p, MAXLEN_PARAM_VALUE);
97 }
98 }
99 break;
100 case PARAM_INT:
101 {
102 int *old_int = (int *)((char *)&All + off);
103 int *new_int = (int *)((char *)&all + off);
104
105 if(*new_int != *old_int)
106 {
107 mpi_printf("RESTART: %s modified from %d to %d while restarting at Time=%g\n", All.ParametersTag[i], *old_int,
108 *new_int, All.Time);
109 *old_int = *new_int;
110 }
111 }
112 break;
113 }
114 }
115 }
116
117 /* change in the output list table is always allowed */
119 memcpy(All.OutputListTimes, all.OutputListTimes, sizeof(double) * All.OutputListLength);
120 memcpy(All.OutputListFlag, all.OutputListFlag, sizeof(char) * All.OutputListLength);
121
122 /* if the final time is changed, we process this with a special function */
123 if(All.TimeMax != all.TimeMax)
124 readjust_timebase(All.TimeMax, all.TimeMax);
125}
126
127void restart::backup_restartfiles(int task)
128{
129 char buf[MAXLEN_PATH_EXTRA];
130 char buf_bak[MAXLEN_PATH_EXTRA];
131 FILE *fcheck = NULL;
132 int bak_files_status = 0;
133
134 mpi_printf("RESTART: Backing up restart files...\n");
135
136 sprintf(buf, "%s/restartfiles/%s.%d", All.OutputDir, "restart", task);
137 sprintf(buf_bak, "%s/restartfiles/bak-%s.%d", All.OutputDir, "restart", task);
138
139 if((fcheck = fopen(buf, "r")))
140 {
141 fclose(fcheck);
142
143 rename(buf, buf_bak);
144
145 bak_files_status = 1;
146 }
147
148 int bak_files_status_sum;
149 MPI_Allreduce(&bak_files_status, &bak_files_status_sum, 1, MPI_INT, MPI_SUM, Communicator);
150
151 if(bak_files_status_sum != NTask && bak_files_status_sum != 0)
152 mpi_printf("RESTART: some (%d) restart files were renamed to bak, but some (%d) weren't - something is very possibly wrong!",
153 bak_files_status, NTask - bak_files_status);
154 else if(bak_files_status_sum == NTask)
155 mpi_printf("RESTART: done renaming pre-existing restart files to bak files.\n");
156 else if(bak_files_status_sum == 0)
157 mpi_printf("RESTART: no pre-existing restart files for renaming were found.\n");
158}
159
170void restart::do_restart(int modus)
171{
172#ifdef DO_NOT_PRODUCE_BIG_OUTPUT
173 if(modus == MODUS_WRITE)
174 {
175 mpi_printf("RESTART: Omitting writing restart files.\n");
176 return;
177 }
178#endif
179
180 TIMER_START(CPU_RESTART);
181
182 double t0 = Logs.second();
184
185 if(modus == MODUS_READ)
186 mpi_printf("RESTART: Loading restart files...\n");
187 else if(modus == MODUS_WRITE)
188 mpi_printf("RESTART: Writing restart files.\n");
189
190 /* create directory for restartfiles */
191 if(ThisTask == 0 && modus == MODUS_WRITE)
192 {
193 char buf[MAXLEN_PATH_EXTRA];
194 sprintf(buf, "%s/restartfiles", All.OutputDir);
195 mkdir(buf, 02755);
196 }
197 MPI_Barrier(Communicator);
198
200 {
201 mpi_printf("NOTICE: MaxFilesWithConcurrentIO has been reduced to the number of processors\n");
203 }
204
206 {
207 mpi_printf("NOTICE: MaxFilesWithConcurrentIO has been set to be equal to the number of processors\n");
209 }
210
211 files_concurrent = All.MaxFilesWithConcurrentIO;
212
213 files_groups = NTask / All.MaxFilesWithConcurrentIO;
214
216 files_groups++;
217
218 if(modus == MODUS_WRITE)
219 backup_restartfiles(ThisTask);
220
221 /* now work the I/O of the files, controlled by scheduler to achieve optimum I/O bandwidth under the constraint of a maximum number
222 * for the concurrent file access */
223 work_files(modus);
224
225 /* check whether the restarts are all at the same time */
226 if(modus == MODUS_READ) /* read */
227 {
229
230 if(ThisTask == 0)
231 all_task0 = All;
232
233 MPI_Bcast(&all_task0, sizeof(global_data_all_processes), MPI_BYTE, 0, Communicator);
234
235 if(all_task0.Time != All.Time)
236 Terminate("The restart file on task=%d is not consistent with the one on task=0\n", ThisTask);
237 }
238
239 long long byte_count = get_io_byte_count(), byte_count_all;
240 sumup_longs(1, &byte_count, &byte_count_all, Communicator);
241
242 double t1 = Logs.second();
243
244 mpi_printf("RESTART: done. load/save took %g sec, total size %g MB, corresponds to effective I/O rate of %g MB/sec\n",
245 Logs.timediff(t0, t1), byte_count_all / (1024.0 * 1024.0), byte_count_all / (1024.0 * 1024.0) / Logs.timediff(t0, t1));
246
247 TIMER_STOP(CPU_RESTART);
248}
249
250void restart::polling(int modus)
251{
252 if(ThisTask == 0)
253 if(files_completed < NTask)
254 {
255 MPI_Status status;
256 int flag;
257
258 /* now check for a completion message */
259 MPI_Iprobe(MPI_ANY_SOURCE, TAG_KEY, Communicator, &flag, &status);
260
261 if(flag)
262 {
263 int source = status.MPI_SOURCE;
264
265 int dummy;
266 MPI_Recv(&dummy, 1, MPI_INT, source, TAG_KEY, Communicator, MPI_STATUS_IGNORE);
267 files_completed++;
268
269 if(files_started < NTask)
270 {
271 if((files_started % files_concurrent) == 0)
272 {
273 if(modus == MODUS_READ)
274 mpi_printf("RESTART: Loading restart files group #%d out of %d...\n", (files_started / files_concurrent) + 1,
275 files_groups);
276 else if(modus == MODUS_WRITE)
277 mpi_printf("RESTART: Writing restart files group #%d out of %d...\n", (files_started / files_concurrent) + 1,
278 files_groups);
279 }
280
281 /* send start signal */
282 MPI_Ssend(&ThisTask, 1, MPI_INT, seq[files_started++].thistask, TAG_N, Communicator);
283 }
284 }
285 }
286}
287
288void restart::work_files(int modus)
289{
290 if(ThisTask == 0)
291 if(!(seq = (seq_data *)malloc(NTask * sizeof(seq_data))))
292 Terminate("can't allocate seq_data");
293
294 seq_data seq_loc;
295 seq_loc.thistask = ThisTask;
296 seq_loc.rankinnode = RankInThisNode;
297 seq_loc.thisnode = ThisNode;
298
299 MPI_Gather(&seq_loc, sizeof(seq_data), MPI_BYTE, seq, sizeof(seq_data), MPI_BYTE, 0, Communicator);
300
301 if(modus == MODUS_READ)
303
304 if(ThisTask == 0)
305 {
306 std::sort(seq, seq + NTask);
307
308 files_started = 0;
309 files_completed = 0;
310
311 if((files_started % files_concurrent) == 0)
312 {
313 if(modus == MODUS_READ)
314 mpi_printf("RESTART: Loading restart files group #%d out of %d...\n", (files_started / files_concurrent) + 1,
315 files_groups);
316 else if(modus == MODUS_WRITE)
317 mpi_printf("RESTART: Writing restart files group #%d out of %d...\n", (files_started / files_concurrent) + 1,
318 files_groups);
319 }
320
321 for(int i = 1; i < All.MaxFilesWithConcurrentIO; i++)
322 {
323 files_started++;
324 MPI_Ssend(&ThisTask, 1, MPI_INT, seq[i].thistask, TAG_N, Communicator);
325 }
326
327 files_started++;
328 contents_restart_file(modus);
329 files_completed++;
330
331 if(files_started < NTask)
332 {
333 if((files_started % files_concurrent) == 0)
334 {
335 if(modus == MODUS_READ)
336 mpi_printf("RESTART: Loading restart files group #%d out of %d...\n", (files_started / files_concurrent) + 1,
337 files_groups);
338 else if(modus == MODUS_WRITE)
339 mpi_printf("RESTART: Writing restart files group #%d out of %d...\n", (files_started / files_concurrent) + 1,
340 files_groups);
341 }
342
343 /* send start signal */
344 MPI_Ssend(&ThisTask, 1, MPI_INT, seq[files_started++].thistask, TAG_N, Communicator);
345 }
346
347 while(files_completed < NTask)
348 polling(modus);
349
350 free(seq);
351 }
352 else
353 {
354 /* wait for start signal */
355 int dummy;
356 MPI_Recv(&dummy, 1, MPI_INT, 0, TAG_N, Communicator, MPI_STATUS_IGNORE); /* wait until we are told to start */
357
358 contents_restart_file(modus);
359
360 /* send back completion notice */
361 MPI_Ssend(&ThisTask, 1, MPI_INT, 0, TAG_KEY, Communicator);
362 }
363
364 if(modus == MODUS_READ)
366}
367
368void restart::contents_restart_file(int modus)
369{
370 char buf[MAXLEN_PATH_EXTRA];
371 sprintf(buf, "%s/restartfiles/%s.%d", All.OutputDir, "restart", ThisTask);
372
373 if(modus == MODUS_READ)
374 {
375 if(!(fd = fopen(buf, "r")))
376 {
377 Terminate("RESTART: Restart file '%s' not found.\n", buf);
378 }
379 }
380 else if(modus == MODUS_WRITE)
381 {
382 if(!(fd = fopen(buf, "w")))
383 {
384 Terminate("RESTART: Restart file '%s' cannot be opened.\n", buf);
385 }
386 }
387 else
388 Terminate("unknown modus\n");
389
390 /* common data */
391 byten(All.get_data_ptr(), All.get_data_size(), modus);
392
393 /* converter data to integer coordinates*/
394 intposconvert *converter = &Sim->Sp;
395 byten(converter, sizeof(intposconvert), modus);
396
397 in(&Sim->Sp.MaxPart, modus);
398 in(&Sim->Sp.MaxPartSph, modus);
399 byten(&Sim->Sp.TotNumPart, sizeof(Sim->Sp.TotNumPart), modus);
400 byten(&Sim->Sp.TotNumGas, sizeof(Sim->Sp.TotNumGas), modus);
401
402 if(modus == MODUS_READ) /* read */
403 Sim->Sp.allocate_memory();
404
405 in(&Sim->Sp.NumPart, modus);
406
407 /* Particle data */
408 byten(&Sim->Sp.P[0], Sim->Sp.NumPart * sizeof(particle_data), modus);
409
410 in(&Sim->Sp.NumGas, modus);
411
412 if(Sim->Sp.NumGas > 0)
413 {
414 /* Sph-Particle data */
415 byten(&Sim->Sp.SphP[0], Sim->Sp.NumGas * sizeof(sph_particle_data), modus);
416 }
417
418#if defined(MERGERTREE) && defined(SUBFIND)
419 byten(&Sim->MergerTree.PrevTotNsubhalos, sizeof(long long), modus);
420 byten(&Sim->MergerTree.PrevNsubhalos, sizeof(int), modus);
421#endif
422
423 /* lightcone particle data */
424#ifdef LIGHTCONE_PARTICLES
425 /* converter data to integer coordinates*/
426 intposconvert *converter_lp = &Sim->Lp;
427 byten(converter_lp, sizeof(intposconvert), modus);
428
429 in(&Sim->Lp.MaxPart, modus);
430 byten(&Sim->Lp.TotNumPart, sizeof(Sim->Lp.TotNumPart), modus);
431
432 if(modus == MODUS_READ) /* read */
433 Sim->Lp.allocate_memory();
434
435 in(&Sim->Lp.NumPart, modus);
436 byten(&Sim->Lp.P[0], Sim->Lp.NumPart * sizeof(lightcone_particle_data), modus);
437
438 in(&Sim->LightCone.NumLastCheck, modus);
439#endif
440
441 /* lightcone massmap data */
442#ifdef LIGHTCONE_MASSMAPS
443 in(&Sim->Mp.MaxPart, modus);
444
445 if(modus == MODUS_READ)
446 Sim->Mp.allocate_memory();
447
448 in(&Sim->Mp.NumPart, modus);
449 byten(&Sim->Mp.P[0], Sim->Mp.NumPart * sizeof(lightcone_massmap_data), modus);
450
451 /* allocate and clear local piece of mass map if needed */
452 if(modus == MODUS_READ)
453 {
454 Sim->LightCone.Mp->Npix = nside2npix(All.LightConeMassMapsNside);
455 subdivide_evenly(Sim->LightCone.Mp->Npix, NTask, ThisTask, &Sim->LightCone.Mp->FirstPix, &Sim->LightCone.Mp->NpixLoc);
456
457 Sim->LightCone.MassMap =
458 (double *)Mem.mymalloc_movable_clear(&Sim->LightCone.MassMap, "MassMap", Sim->LightCone.Mp->NpixLoc * sizeof(double));
459 }
460
461 byten(Sim->LightCone.MassMap, Sim->LightCone.Mp->NpixLoc * sizeof(double), modus);
462#endif
463
464 /* write state of random number generator */
465 byten(gsl_rng_state(random_generator), gsl_rng_size(random_generator), modus);
466
467 byten(Logs.CPU_Step, logs::CPU_LAST * sizeof(double), modus);
468 byten(Logs.CPU_Step_Stored, logs::CPU_LAST * sizeof(double), modus);
469 byten(Logs.CPU_Sum, logs::CPU_LAST * sizeof(double), modus);
470
471 /* now store variables for time integration bookkeeping */
472 byten(Sim->Sp.TimeBinSynchronized, TIMEBINS * sizeof(int), modus);
473
474 in(&Sim->Sp.TimeBinsHydro.NActiveParticles, modus);
475 in(&Sim->Sp.TimeBinsGravity.NActiveParticles, modus);
476 byten(&Sim->Sp.TimeBinsHydro.GlobalNActiveParticles, sizeof(long long), modus);
477 byten(&Sim->Sp.TimeBinsGravity.GlobalNActiveParticles, sizeof(long long), modus);
478 byten(Sim->Sp.TimeBinsHydro.ActiveParticleList, Sim->Sp.TimeBinsHydro.NActiveParticles * sizeof(int), modus);
479 byten(Sim->Sp.TimeBinsGravity.ActiveParticleList, Sim->Sp.TimeBinsGravity.NActiveParticles * sizeof(int), modus);
480 byten(Sim->Sp.TimeBinsHydro.NextInTimeBin, Sim->Sp.NumGas * sizeof(int), modus);
481 byten(Sim->Sp.TimeBinsGravity.NextInTimeBin, Sim->Sp.NumPart * sizeof(int), modus);
482 byten(Sim->Sp.TimeBinsHydro.PrevInTimeBin, Sim->Sp.NumGas * sizeof(int), modus);
483 byten(Sim->Sp.TimeBinsGravity.PrevInTimeBin, Sim->Sp.NumPart * sizeof(int), modus);
484 byten(Sim->Sp.TimeBinsHydro.TimeBinCount, TIMEBINS * sizeof(int), modus);
485 byten(Sim->Sp.TimeBinsGravity.TimeBinCount, TIMEBINS * sizeof(int), modus);
486 byten(Sim->Sp.TimeBinsHydro.FirstInTimeBin, TIMEBINS * sizeof(int), modus);
487 byten(Sim->Sp.TimeBinsGravity.FirstInTimeBin, TIMEBINS * sizeof(int), modus);
488 byten(Sim->Sp.TimeBinsHydro.LastInTimeBin, TIMEBINS * sizeof(int), modus);
489 byten(Sim->Sp.TimeBinsGravity.LastInTimeBin, TIMEBINS * sizeof(int), modus);
490
491#ifdef STARFORMATION
492 byten(Sim->Sp.TimeBinSfr, TIMEBINS * sizeof(double), modus);
493#endif
494
495 /* now store relevant data for tree */
496
497 in(&Sim->Domain.NTopleaves, modus);
498 in(&Sim->Domain.NTopnodes, modus);
499
500 in(&Sim->NgbTree.MaxPart, modus);
501 in(&Sim->NgbTree.MaxNodes, modus);
502 in(&Sim->NgbTree.NumNodes, modus);
503 in(&Sim->NgbTree.NumPartImported, modus);
504 in(&Sim->NgbTree.FirstNonTopLevelNode, modus);
505 in(&Sim->NgbTree.ImportedNodeOffset, modus);
506 in(&Sim->NgbTree.EndOfTreePoints, modus);
507 in(&Sim->NgbTree.EndOfForeignNodes, modus);
508
509 if(modus == MODUS_READ)
510 {
511 Sim->Domain.domain_allocate(Sim->Domain.NTopnodes);
512
513 /* passing a negative number to the allocate call will here prevent that NgbTree.MaxPart and NgbTree.MaxNodes are recomputed */
514 Sim->NgbTree.treeallocate(-1, &Sim->Sp, &Sim->Domain);
515
516 if(Sim->NgbTree.MaxPart != 0)
517 {
518 Sim->NgbTree.Points = (ngbpoint_data *)Mem.mymalloc_movable(&Sim->NgbTree.Points, "Points",
519 Sim->NgbTree.NumPartImported * sizeof(ngbpoint_data));
520 Sim->NgbTree.Nextnode = (int *)Mem.mymalloc_movable(
521 &Sim->NgbTree.Nextnode, "Nextnode",
522 (Sim->NgbTree.MaxPart + Sim->Domain.NTopleaves + Sim->NgbTree.NumPartImported) * sizeof(int));
523 Sim->NgbTree.Father = (int *)Mem.mymalloc_movable(&Sim->NgbTree.Father, "Father",
524 (Sim->NgbTree.MaxPart + Sim->NgbTree.NumPartImported) * sizeof(int));
525 }
526 }
527
528 if(Sim->Sp.TotNumGas > 0)
529 {
530 byten(Sim->NgbTree.Nodes + Sim->NgbTree.MaxPart + Sim->Domain.NTopnodes,
531 (Sim->NgbTree.NumNodes - Sim->Domain.NTopnodes) * sizeof(ngbnode), modus);
532 byten(Sim->NgbTree.Nextnode, (Sim->NgbTree.MaxPart + Sim->Domain.NTopleaves) * sizeof(int), modus);
533 byten(Sim->NgbTree.Father, Sim->NgbTree.MaxPart * sizeof(int), modus);
534
535 if(Sim->NgbTree.TreeSharedMem_ThisTask == 0)
536 {
537 byten(Sim->NgbTree.TopNodes + Sim->NgbTree.MaxPart, Sim->Domain.NTopnodes * sizeof(ngbnode), modus);
538 byten(Sim->NgbTree.NodeIndex, Sim->Domain.NTopleaves * sizeof(int), modus);
539 byten(Sim->NgbTree.NodeSibling, Sim->Domain.NTopleaves * sizeof(int), modus);
540 byten(Sim->NgbTree.NodeLevel, Sim->Domain.NTopleaves * sizeof(unsigned char), modus);
541 }
542 }
543
544 byten(Sim->Domain.TopNodes, Sim->Domain.NTopnodes * Sim->Domain.domain_sizeof_topnode_data(), modus);
545 byten(Sim->Domain.TaskOfLeaf, Sim->Domain.NTopleaves * sizeof(int), modus);
546 byten(Sim->Domain.ListOfTopleaves, Sim->Domain.NTopleaves * sizeof(int), modus);
547 byten(Sim->Domain.FirstTopleafOfTask, NTask * sizeof(int), modus);
548 byten(Sim->Domain.NumTopleafOfTask, NTask * sizeof(int), modus);
549
550 fclose(fd);
551}
552
563void restart::readjust_timebase(double TimeMax_old, double TimeMax_new)
564{
565 mpi_printf("\nRESTART: All.TimeMax has been changed in the parameterfile from %g to %g. Need to adjust integer timeline.\n",
566 TimeMax_old, TimeMax_new);
567
568 if(TimeMax_new < TimeMax_old)
569 Terminate("\nIt is not allowed to reduce All.TimeMax\n");
570
571 long long ti_end;
572
574 ti_end = (long long)(log(TimeMax_new / All.TimeBegin) / All.Timebase_interval);
575 else
576 ti_end = (long long)((TimeMax_new - All.TimeBegin) / All.Timebase_interval);
577
578 while(ti_end > TIMEBASE)
579 {
580 All.Timebase_interval *= 2.0;
581
582 ti_end /= 2;
583 All.Ti_Current /= 2;
584
585#if defined(PMGRID) && !defined(TREEPM_NOTIMESPLIT)
586 All.PM_Ti_begstep /= 2;
587 All.PM_Ti_endstep /= 2;
588#endif
589
590 for(int i = 0; i < Sim->Sp.NumPart; i++)
591 {
592 if(Sim->Sp.P[i].TimeBinGrav > 0)
593 {
594 Sim->Sp.P[i].Ti_Current = Sim->Sp.P[i].Ti_Current / 2;
595
596 Sim->Sp.P[i].TimeBinGrav--;
597
598 if(Sim->Sp.P[i].TimeBinGrav <= 0)
599 Terminate("Error in readjust_timebase(). Minimum Timebin for particle %d reached.\n", i);
600 }
601
602 if(Sim->Sp.P[i].getType() == 0)
603 {
604 if(Sim->Sp.P[i].getTimeBinHydro() > 0)
605 {
606 Sim->Sp.P[i].setTimeBinHydro(Sim->Sp.P[i].getTimeBinHydro() - 1);
607
608 if(Sim->Sp.P[i].getTimeBinHydro() <= 0)
609 Terminate("Error in readjust_timebase(). Minimum Timebin (hydro) for sph particle %d reached.\n", i);
610 }
611 }
612 }
613 }
614
615 All.TimeMax = TimeMax_new;
616}
617
618void restart::byten(void *x, size_t n, int modus)
619{
620 char *p = (char *)x;
621
622 while(n > BLKSIZE)
623 {
624 byten_doit(p, BLKSIZE, modus);
625 p += BLKSIZE;
626 n -= BLKSIZE;
627 polling(modus);
628 }
629
630 if(n > 0)
631 byten_doit(p, n, modus);
632}
633
636void restart::byten_doit(void *x, size_t n, int modus)
637{
638 if(modus == MODUS_READ)
639 my_fread(x, n, 1, fd);
640 else
641 my_fwrite(x, n, 1, fd);
642}
643
650void restart::in(int *x, int modus) { byten(x, sizeof(int), modus); }
global_data_all_processes All
Definition: main.cc:40
long long byte_count
size_t my_fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
A wrapper for the fread() function.
void reset_io_byte_count(void)
long long get_io_byte_count(void)
size_t my_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
A wrapper for the fwrite() function.
double CPU_Step[CPU_LAST]
Definition: logs.h:115
double CPU_Sum[CPU_LAST]
Definition: logs.h:117
double CPU_Step_Stored[CPU_LAST]
Definition: logs.h:116
double timediff(double t0, double t1)
Definition: logs.cc:488
double second(void)
Definition: logs.cc:471
char ParametersType[MAX_PARAMETERS]
Definition: parameters.h:46
char ParametersTag[MAX_PARAMETERS][MAXLEN_PARAM_TAG]
Definition: parameters.h:44
int NParameters
Definition: parameters.h:42
void * ParametersValue[MAX_PARAMETERS]
Definition: parameters.h:45
char ParametersChangeable[MAX_PARAMETERS]
Definition: parameters.h:47
void write(sim *Sim_ptr)
Definition: restart.cc:37
void load(sim *Sim_ptr)
This function loads the last restart file.
Definition: restart.cc:50
int ThisNode
Definition: setcomm.h:36
void mpi_printf(const char *fmt,...)
Definition: setcomm.h:55
int ThisTask
Definition: setcomm.h:33
int NTask
Definition: setcomm.h:32
int RankInThisNode
Definition: setcomm.h:39
MPI_Comm Communicator
Definition: setcomm.h:31
int Island_Smallest_WorldTask
Definition: simulation.h:50
domain< simparticles > Domain
Definition: simulation.h:58
sph NgbTree
Definition: simulation.h:68
simparticles Sp
Definition: simulation.h:56
long long TotNumPart
Definition: simparticles.h:46
long long TotNumGas
Definition: simparticles.h:47
void allocate_memory(void)
Definition: simparticles.h:273
TimeBinData TimeBinsGravity
Definition: simparticles.h:205
particle_data * P
Definition: simparticles.h:54
sph_particle_data * SphP
Definition: simparticles.h:59
TimeBinData TimeBinsHydro
Definition: simparticles.h:204
int TimeBinSynchronized[TIMEBINS]
Definition: simparticles.h:203
int TreeSharedMem_ThisTask
Definition: tree.h:162
int FirstNonTopLevelNode
Definition: tree.h:152
void treeallocate_share_topnode_addresses(void)
Definition: tree.cc:890
int MaxPart
Definition: tree.h:136
int * NodeIndex
Definition: tree.h:107
point_data * Points
Definition: tree.h:127
MPI_Comm TreeSharedMemComm
Definition: tree.h:161
void treeallocate(int max_partindex, partset *Pptr, domain< partset > *Dptr)
Definition: tree.cc:776
int * NodeSibling
Definition: tree.h:106
unsigned char * NodeLevel
Definition: tree.h:125
int NumPartImported
Definition: tree.h:139
node * TopNodes
Definition: tree.h:109
int EndOfForeignNodes
Definition: tree.h:155
int NumNodes
Definition: tree.h:138
node * Nodes
Definition: tree.h:110
int MaxNodes
Definition: tree.h:137
int * Nextnode
Definition: tree.h:105
int ImportedNodeOffset
Definition: tree.h:157
int * Father
Definition: tree.h:104
int EndOfTreePoints
Definition: tree.h:154
#define TIMEBINS
Definition: constants.h:332
#define MAXLEN_PATH_EXTRA
Definition: constants.h:301
#define TIMEBASE
Definition: constants.h:333
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
shmem Shmem
Definition: main.cc:45
#define TAG_N
Definition: mpi_utils.h:25
#define TAG_KEY
Definition: mpi_utils.h:29
void sumup_longs(int n, long long *src, long long *res, MPI_Comm comm)
memory Mem
Definition: main.cc:44
expr log(half arg)
Definition: half.hpp:2745
#define PARAM_CHANGEABLE
Definition: parameters.h:23
#define PARAM_INT
Definition: parameters.h:20
#define MAXLEN_PARAM_VALUE
Definition: parameters.h:26
#define PARAM_STRING
Definition: parameters.h:19
#define PARAM_DOUBLE
Definition: parameters.h:18
#define MODUS_READ
Definition: restart.h:16
#define MODUS_WRITE
Definition: restart.h:15
#define BLKSIZE
Definition: restart.h:18
int NActiveParticles
Definition: timestep.h:18
int * ActiveParticleList
Definition: timestep.h:20
int TimeBinCount[TIMEBINS]
Definition: timestep.h:21
int FirstInTimeBin[TIMEBINS]
Definition: timestep.h:23
long long GlobalNActiveParticles
Definition: timestep.h:19
int * PrevInTimeBin
Definition: timestep.h:26
int * NextInTimeBin
Definition: timestep.h:25
int LastInTimeBin[TIMEBINS]
Definition: timestep.h:24
integertime Ti_Current
Definition: allvars.h:188
char OutputDir[MAXLEN_PATH]
Definition: allvars.h:272
double OutputListTimes[MAXLEN_OUTPUTLIST]
Definition: allvars.h:275
size_t get_data_size(void)
Definition: allvars.h:362
char OutputListFlag[MAXLEN_OUTPUTLIST]
Definition: allvars.h:276
char * get_data_ptr(void)
Definition: allvars.h:360
std::atomic< integertime > Ti_Current
Definition: particle_data.h:60
unsigned char getTimeBinHydro(void)
signed char TimeBinGrav
Definition: particle_data.h:71
unsigned char getType(void)
void setTimeBinHydro(unsigned char bin)
gsl_rng * random_generator
Definition: system.cc:40
void subdivide_evenly(long long N, int pieces, int index_bin, long long *first, int *count)
Definition: system.cc:51