/
main.c
115 lines (93 loc) · 2.85 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <math.h>
#include <gsl/gsl_math.h>
#include "allvars.h"
#include "proto.h"
/*! \file main.c
* \brief start of the program
*/
/*
* This file was originally part of the GADGET3 code developed by
* Volker Springel (volker.springel@h-its.org). The code has been modified
* in part by Phil Hopkins (phopkins@caltech.edu) for GIZMO.
*/
/*!
* 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.
*/
int main(int argc, char **argv)
{
int i;
#ifdef IMPOSE_PINNING
get_core_set();
#endif
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &ThisTask);
MPI_Comm_size(MPI_COMM_WORLD, &NTask);
#ifdef IMPOSE_PINNING
pin_to_core_set();
#endif
mpi_report_comittable_memory(0);
MPI_Barrier(MPI_COMM_WORLD);
/* initialize OpenMP thread pool and bind (implicitly though OpenMP runtime) */
#ifdef _OPENMP
#pragma omp parallel
{
#pragma omp master
{
maxThreads = omp_get_num_threads();
if(ThisTask == 0)
printf("Using %d OpenMP threads\n", maxThreads);
}
}
#elif defined(OMP_NUM_THREADS)
if(ThisTask == 0)
printf("Using %d POSIX threads\n", maxThreads);
#endif
for(PTask = 0; NTask > (1 << PTask); PTask++);
if(argc < 2)
{
if(ThisTask == 0)
{
printf("Parameters are missing.\n");
printf("Call with <ParameterFile> [<RestartFlag>] [<RestartSnapNum>]\n");
printf("\n");
printf(" RestartFlag Action\n");
printf(" 0 Read initial conditions and start simulation\n");
printf(" 1 Read restart files and resume simulation\n");
printf(" 2 Restart from specified snapshot dump and continue simulation\n");
printf(" 3 Run FLAG_NOT_IN_PUBLIC_CODE and optionally FLAG_NOT_IN_PUBLIC_CODE if enabled\n");
printf(" 4 Convert snapshot file to different format\n");
printf(" 5 Calculate power spectrum and two-point function\n");
printf(" 6 Calculate velocity power spectrum for the gas particles\n");
printf("\n");
}
endrun(0);
}
strcpy(ParameterFile, argv[1]);
if(argc >= 3)
RestartFlag = atoi(argv[2]);
else
RestartFlag = 0;
if(argc >= 4)
RestartSnapNum = atoi(argv[3]);
else
RestartSnapNum = -1;
/* initialize CPU-time/Wallclock-time measurement */
for(i = 0; i < CPU_PARTS; i++)
All.CPU_Sum[i] = CPU_Step[i] = 0;
CPUThisRun = 0;
WallclockTime = my_second();
begrun(); /* set-up run */
run(); /* main simulation loop */
MPI_Finalize(); /* clean up & finalize MPI */
return 0;
}