12#include "gadgetconfig.h"
14#include <gsl/gsl_math.h>
22#include "../cooling_sfr/cooling.h"
23#include "../data/allvars.h"
24#include "../data/dtypes.h"
25#include "../half/half.hpp"
27#include "../io/restart.h"
28#include "../io/snap_io.h"
29#include "../logs/logs.h"
30#include "../main/main.h"
31#include "../main/simulation.h"
32#include "../mergertree/mergertree.h"
33#include "../mpi_utils/shared_mem_handler.h"
34#include "../ngenic/ngenic.h"
35#include "../system/system.h"
36#include "../time_integration/driftfac.h"
55int main(
int argc,
char **argv)
63 MPI_Init(&argc, &argv);
68#if NUMBER_OF_MPI_LISTENERS_PER_NODE > 1
69 MPI_Comm fullsharedmemnode;
70 MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, 0, MPI_INFO_NULL, &fullsharedmemnode);
72 int fullsharedmemnode_ThisTask, fullsharedmemnode_NTask;
73 MPI_Comm_rank(fullsharedmemnode, &fullsharedmemnode_ThisTask);
74 MPI_Comm_size(fullsharedmemnode, &fullsharedmemnode_NTask);
79 MPI_Comm_split(fullsharedmemnode, bin, fullsharedmemnode_ThisTask, &
Shmem.
SharedMemComm);
81 MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, 0, MPI_INFO_NULL, &
Shmem.
SharedMemComm);
87 int min_ntask, max_ntask;
88 MPI_Allreduce(&
Shmem.
Island_NTask, &max_ntask, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD);
89 MPI_Allreduce(&
Shmem.
Island_NTask, &min_ntask, 1, MPI_INT, MPI_MIN, MPI_COMM_WORLD);
93 printf(
"Shared memory islands host a minimum of %d and a maximum of %d MPI ranks.\n", min_ntask, max_ntask);
105 MPI_Allreduce(&
Shmem.
GhostRank, &comm_ranks, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
108 printf(
"We shall use %d MPI ranks in total for assisting one-sided communication (%d per shared memory node).\n",
114 Terminate(
"We have shared memory islands with just one MPI rank -- can't put aside this one just for communication");
121 "We have shared memory islands with %d MPI ranks, which is larger than MAX_NUMBER_OF_RANKS_WITH_SHARED_MEMORY=%d\n"
122 "You may consider increasing NUMBER_OF_MPI_LISTENERS_PER_NODE, current value is %d\n",
147 Sim.determine_compute_nodes();
165#ifdef HOST_MEMORY_REPORTING
166 Sim.mpi_report_comittable_memory();
173 if(Sim.ThisTask == 0)
175 printf(
"\nParameters are missing.\n");
176 printf(
"Start as ./Gadget4 <ParameterFile> [<RestartFlag>] [<SpecialOptions>]\n");
178 printf(
" RestartFlag Action\n");
179 printf(
" %2d Read initial conditions and start simulation\n",
RST_BEGIN);
180 printf(
" %2d Read restart files and resume simulation\n",
RST_RESUME);
181 printf(
" %2d Restart from specified snapshot dump and resume simulation\n",
RST_STARTFROMSNAP);
182 printf(
" %2d Run FOF and optionally SUBFIND\n",
RST_FOF);
183 printf(
" %2d Calculate a matter power spectrum\n",
RST_POWERSPEC);
184 printf(
" %2d Convert snapshot file to different format [input=ICFormat output=SnapFormat\n",
RST_CONVERTSNAP);
185 printf(
" %2d Create cosmological initial conditions\n",
RST_CREATEICS);
186 printf(
" %2d Calculate descendants/progenitors [connecting group catalogues SnapNum-1 and SnapNum]\n",
188 printf(
" %2d Arrange halos in merger trees [using group catalogues up to SnapNum]\n",
RST_MAKETREES);
189 printf(
" %2d Carry out I/O bandwidth test to determine best setting for number of concurrent reads/writes\n",
191 printf(
" %2d Rearrange particle-lightcone data in merger tree order <conenr> <firstnum> <lastnum>\n",
193 printf(
" %2d Rearrange most-bound snapshot data in merger tree order <firstnum> <lastnum>\n",
207 int restartSnapNum = -1;
209 restartSnapNum = atoi(argv[3]);
216 Terminate(
"Need to give the snapshot number for the chosen option.\n");
220 Sim.begrun1(argv[1]);
254 Sim.MergerTree.descendants_in_postprocessing(restartSnapNum);
257 Terminate(
"Compile with option MERGERTREE for this option");
264 Sim.MergerTree.halotrees_construct(restartSnapNum);
267 Terminate(
"Compile with option MERGERTREE for this option");
273 Sim.measure_io_bandwidth();
279#if defined(LIGHTCONE) && defined(LIGHTCONE_PARTICLES) && defined(REARRANGE_OPTION)
280 Sim.rearrange_lightcone(argc, argv);
282 Terminate(
"need to compile with REARRANGE_OPTION for this option to work\n");
289#if defined(MERGERTREE) && defined(REARRANGE_OPTION)
290 Sim.rearrange_snapshot(argc, argv);
292 Terminate(
"need to compile with REARRANGE_OPTION for this option to work\n");
299 Sim.Ngenic.create_grid();
312 Sim.CoolSfr.InitCool();
315 Sim.mpi_printf(
"Start writing file %s\nSnapNum %d\n",
All.
SnapshotFileBase, restartSnapNum);
323 Sim.init(restartSnapNum);
Ewald correction functionality.
void init_cpu_log(simparticles *Sp_ptr)
void detect_topology(void)
void pin_to_core_set(setcomm *sc)
void determine_compute_nodes(void)
long long SharedMemoryOnNode
void initcomm(MPI_Comm Comm)
void shared_memory_handler(void)
int Island_Smallest_WorldTask
void read_ic(const char *fname)
This function reads initial conditions that are in on of the default file formats of Gadget.
void write_snapshot(int num, mysnaptype snap_type)
Save snapshot to disk.
#define MAXLEN_PATH_EXTRA
#define NUMBER_OF_MPI_LISTENERS_PER_NODE
#define MAX_NUMBER_OF_RANKS_WITH_SHARED_MEMORY
int main(int argc, char **argv)
global_data_all_processes All
enum restart_options RestartFlag
char OutputDir[MAXLEN_PATH]
char SnapshotFileBase[MAXLEN_PATH]
char InitCondFile[MAXLEN_PATH]
void subdivide_evenly_get_bin(int N, int pieces, int index, int *bin)