MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
Functions
main.c File Reference

start of the program More...

#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/resource.h>
#include <unistd.h>
#include <math.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_errno.h>
#include <omp.h>
#include <libgadget/slotsmanager.h>
#include <libgadget/partmanager.h>
#include <libgadget/run.h>
#include <libgadget/checkpoint.h>
#include <libgadget/config.h>
#include <libgadget/utils.h>
#include "params.h"
Include dependency graph for main.c:

Go to the source code of this file.

Functions

void gsl_handler (const char *reason, const char *file, int line, int gsl_errno)
 
int main (int argc, char **argv)
 

Detailed Description

start of the program

Definition in file main.c.

Function Documentation

◆ gsl_handler()

void gsl_handler ( const char *  reason,
const char *  file,
int  line,
int  gsl_errno 
)

Definition at line 24 of file main.c.

25 {
26  endrun(2001,"GSL_ERROR in file: %s, line %d, errno:%d, error: %s\n",file, line, gsl_errno, reason);
27 }
void endrun(int where, const char *fmt,...)
Definition: endrun.c:147

References endrun().

Referenced by main().

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

◆ main()

int main ( int  argc,
char **  argv 
)

This function initializes the MPI communication packages, and sets cpu-time counters to 0. Then begrun() is called, which sets up the simulation either from IC's or from restart files. Finally, run() is started, the main simulation loop, which iterates over the timesteps.

Definition at line 39 of file main.c.

40 {
41  int NTask;
42  int thread_provided;
43  MPI_Init_thread(&argc, &argv, MPI_THREAD_FUNNELED, &thread_provided);
44  MPI_Comm_size(MPI_COMM_WORLD, &NTask);
45  if(thread_provided != MPI_THREAD_FUNNELED)
46  message(1, "MPI_Init_thread returned %d != MPI_THREAD_FUNNELED\n", thread_provided);
47 
48  if(argc < 2)
49  {
50  message(0, "Parameters are missing.\n");
51  message(0, "Call with <ParameterFile> [<RestartFlag>] [<RestartSnapNum>]\n\n");
52  message(0, " RestartFlag Action\n");
53  message(0, " 1 Restart from last snapshot (LastSnapNum.txt) and continue simulation\n");
54  message(0, " 2 Restart from specified snapshot (-1 for Initial Condition) and continue simulation\n");
55  message(0, " 3 Run FOF if enabled\n");
56  message(0, " 4 Generate a power spectrum and exit\n");
57  message(0, " 99 Run Tests. \n\n");
58  MPI_Finalize();
59  return 1;
60  }
61 
62  message(0, "This is MP-Gadget, version %s.\n", GADGET_VERSION);
63  message(0, "Running on %d MPI Ranks.\n", NTask);
64  message(0, " %d OpenMP Threads.\n", omp_get_max_threads());
65  message(0, "Code was compiled with settings:\n"
66  "%s\n", GADGET_COMPILER_SETTINGS);
67  message(0, "Size of particle structure %td [bytes]\n",sizeof(struct particle_data));
68  message(0, "Size of blackhole structure %td [bytes]\n",sizeof(struct bh_particle_data));
69  message(0, "Size of sph particle structure %td [bytes]\n",sizeof(struct sph_particle_data));
70  message(0, "Size of star particle structure %td [bytes]\n",sizeof(struct star_particle_data));
71 
72  /* Avoid dumping core, except for the master process. For large jobs writing core
73  * with all of main memory can be very bad. */
74  int ThisTask;
75  MPI_Comm_rank(MPI_COMM_WORLD, &ThisTask);
76  if(ThisTask != 0) {
77  struct rlimit rlim = {0};
78  setrlimit(RLIMIT_CORE, &rlim);
79  }
80  tamalloc_init();
81 
82  int ShowBacktrace;
83  double MaxMemSizePerNode;
84  read_parameter_file(argv[1], &ShowBacktrace, &MaxMemSizePerNode); /* ... read in parameters for this run */
85 
86  int RestartFlag, RestartSnapNum;
87 
88  if(argc >= 3)
89  RestartFlag = atoi(argv[2]);
90  else
91  RestartFlag = 2;
92 
93  if(argc >= 4)
94  RestartSnapNum = atoi(argv[3]);
95  else
96  RestartSnapNum = -1;
97 
98  if(RestartFlag == 0) {
99  message(0, "Restart flag of 0 is deprecated. Use 2.\n");
100  RestartFlag = 2;
101  }
102  if(RestartFlag == 1) {
103  RestartSnapNum = find_last_snapshot();
104  }
105  if(RestartFlag == 3 && RestartSnapNum < 0) {
106  endrun(0, "Need to give the snapshot number if FOF is selected for output\n");
107  }
108 
109  /*Set up GSL so it gives a proper MPI termination*/
110  gsl_set_error_handler(gsl_handler);
111 
112  /*Initialize the memory manager*/
113  mymalloc_init(MaxMemSizePerNode);
114 
115  /* Make sure memory has finished initialising on all ranks before doing more.
116  * This may improve stability */
117  MPI_Barrier(MPI_COMM_WORLD);
118 
120 
121  struct header_data head = {0};
122  inttime_t ti_init = begrun(RestartSnapNum, &head);
123 
124  switch(RestartFlag) {
125  case 3:
126  runfof(RestartSnapNum, ti_init, &head);
127  break;
128  case 4:
129  runpower(&head);
130  break;
131  case 99:
132  runtests(RestartSnapNum, ti_init, &head);
133  break;
134  default:
135  run(RestartSnapNum, ti_init, &head); /* main simulation loop */
136  break;
137  }
138  MPI_Finalize(); /* clean up & finalize MPI */
139 
140  return 0;
141 }
const char * GADGET_VERSION
Definition: config.c:7
const char * GADGET_COMPILER_SETTINGS
Definition: config.c:1
void message(int where, const char *fmt,...)
Definition: endrun.c:175
void init_endrun(int backtrace)
Definition: endrun.c:132
static int ShowBacktrace
Definition: endrun.c:100
void gsl_handler(const char *reason, const char *file, int line, int gsl_errno)
Definition: main.c:24
void read_parameter_file(char *fname, int *ShowBacktrace, double *MaxMemSizePerNode)
Definition: params.c:359
void tamalloc_init(void)
Definition: mymalloc.c:29
void mymalloc_init(double MaxMemSizePerNode)
Definition: mymalloc.c:48
void runfof(const int RestartSnapNum, const inttime_t Ti_Current, const struct header_data *header)
Definition: run.c:652
int find_last_snapshot(void)
Definition: run.c:182
void run(const int RestartSnapNum, const inttime_t ti_init, const struct header_data *header)
Definition: run.c:284
void runtests(const int RestartSnapNum, const inttime_t Ti_Current, const struct header_data *header)
Definition: run.c:646
inttime_t begrun(const int RestartSnapNum, struct header_data *head)
Definition: run.c:194
void runpower(const struct header_data *header)
Definition: run.c:691
int ThisTask
Definition: test_exchange.c:23
int NTask
Definition: test_exchange.c:23
int32_t inttime_t
Definition: types.h:8

References begrun(), endrun(), find_last_snapshot(), GADGET_COMPILER_SETTINGS, GADGET_VERSION, gsl_handler(), init_endrun(), message(), mymalloc_init(), NTask, read_parameter_file(), run(), runfof(), runpower(), runtests(), ShowBacktrace, tamalloc_init(), and ThisTask.

Here is the call graph for this function: