MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
Functions
checkpoint.c File Reference
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "petaio.h"
#include "checkpoint.h"
#include "walltime.h"
#include "fof.h"
#include "utils.h"
Include dependency graph for checkpoint.c:

Go to the source code of this file.

Functions

void write_checkpoint (int snapnum, int WriteGroupID, int MetalReturnOn, double Time, const Cosmology *CP, const char *OutputDir, const int OutputDebugFields)
 
void dump_snapshot (const char *dump, const double Time, const Cosmology *CP, const char *OutputDir)
 
int find_last_snapnum (const char *OutputDir)
 

Function Documentation

◆ dump_snapshot()

void dump_snapshot ( const char *  dump,
const double  Time,
const Cosmology CP,
const char *  OutputDir 
)

Definition at line 52 of file checkpoint.c.

53 {
54  struct IOTable IOTable = {0};
57  char * fname = fastpm_strdup_printf("%s/%s", OutputDir, dump);
58  petaio_save_snapshot(fname, &IOTable, 1, Time, CP);
60 }
void destroy_io_blocks(struct IOTable *IOTable)
Definition: petaio.c:1034
void register_io_blocks(struct IOTable *IOTable, int WriteGroupID, int MetalReturnOn)
Definition: petaio.c:909
void petaio_save_snapshot(const char *fname, struct IOTable *IOTable, int verbose, const double atime, const Cosmology *CP)
Definition: petaio.c:151
void register_debug_io_blocks(struct IOTable *IOTable)
Definition: petaio.c:1014
static Cosmology * CP
Definition: power.c:27
char * fastpm_strdup_printf(const char *fmt,...)
Definition: string.c:41
Definition: petaio.h:60

References CP, destroy_io_blocks(), fastpm_strdup_printf(), petaio_save_snapshot(), register_debug_io_blocks(), and register_io_blocks().

Referenced by force_tree_build(), and run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_last_snapnum()

int find_last_snapnum ( const char *  OutputDir)

Definition at line 63 of file checkpoint.c.

64 {
65  /* FIXME: this is very fragile; should be fine */
66  int snapnumber = -1;
67  int ThisTask;
68  MPI_Comm_rank(MPI_COMM_WORLD, &ThisTask);
69  if(ThisTask == 0) {
70  char * buf = fastpm_strdup_printf("%s/Snapshots.txt", OutputDir);
71  FILE * fd = fopen(buf, "r");
72  if(fd == NULL) {
73  snapnumber = -1;
74  } else {
75  double time;
76  char ch;
77  int line = 0;
78  while (!feof(fd)) {
79  int n = fscanf(fd, "%d %lg%c", &snapnumber, &time, &ch);
80 // message(1, "n = %d\n", n);
81  if (n == 3 && ch == '\n') {
82  line ++;
83  continue;
84  }
85  if (n == -1 && feof(fd)) {
86  continue;
87  }
88  endrun(1, "Failed to parse %s:%d for the last snap shot number.\n", buf, line);
89  }
90  fclose(fd);
91  }
92  myfree(buf);
93  }
94 
95  MPI_Bcast(&snapnumber, 1, MPI_INT, 0, MPI_COMM_WORLD);
96  return snapnumber;
97 }
void endrun(int where, const char *fmt,...)
Definition: endrun.c:147
#define myfree(x)
Definition: mymalloc.h:19
int ThisTask
Definition: test_exchange.c:23

References endrun(), fastpm_strdup_printf(), myfree, and ThisTask.

Referenced by find_last_snapshot().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_checkpoint()

void write_checkpoint ( int  snapnum,
int  WriteGroupID,
int  MetalReturnOn,
double  Time,
const Cosmology CP,
const char *  OutputDir,
const int  OutputDebugFields 
)

Definition at line 24 of file checkpoint.c.

25 {
26  walltime_measure("/Misc");
27  /* write snapshot of particles */
28  struct IOTable IOTable = {0};
29  register_io_blocks(&IOTable, WriteGroupID, MetalReturnOn);
30  if(OutputDebugFields)
32 
33  char * fname = petaio_get_snapshot_fname(snapnum, OutputDir);
34  petaio_save_snapshot(fname, &IOTable, 1, Time, CP);
35  myfree(fname);
36 
38  walltime_measure("/Snapshot/Write");
39 
40  int ThisTask;
41  MPI_Comm_rank(MPI_COMM_WORLD, &ThisTask);
42  if(ThisTask == 0) {
43  char * buf = fastpm_strdup_printf("%s/Snapshots.txt", OutputDir);
44  FILE * fd = fopen(buf, "a");
45  fprintf(fd, "%03d %g\n", snapnum, Time);
46  fclose(fd);
47  myfree(buf);
48  }
49 }
char * petaio_get_snapshot_fname(int num, const char *OutputDir)
Definition: petaio.c:207
#define walltime_measure(name)
Definition: walltime.h:8

References CP, destroy_io_blocks(), fastpm_strdup_printf(), myfree, petaio_get_snapshot_fname(), petaio_save_snapshot(), register_debug_io_blocks(), register_io_blocks(), ThisTask, and walltime_measure.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function: