forked from pfhopkins/gizmo-public
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
134 lines (111 loc) · 3.44 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <time.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. 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
double safe_memorypertask = mpi_report_comittable_memory(0,1);
MPI_Barrier(MPI_COMM_WORLD);
/* initialize OpenMP thread pool and bind (implicitly though OpenMP runtime) */
if(ThisTask == 0)
{
char *username = getenv("USER");
char hostname[201]; hostname[200] = '\0';
int have_hn = gethostname(hostname,200);
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
printf("\nSystem time: %s", asctime(timeinfo) );
printf("This is GIZMO, version %d, running on %s as %s.\n",
GIZMO_VERSION,
have_hn == 0 ? hostname : "?",
username ? username : "?"
);
#ifdef BUILDINFO
printf(BUILDINFO", " __DATE__ " " __TIME__ "\n");
#endif
printf("\nCode was compiled with settings:\n\n");
output_compile_time_options();
}
#ifdef _OPENMP
#pragma omp parallel
{
#pragma omp master
{
maxThreads = omp_get_num_threads();
}
}
#elif defined(PTHREADS_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 FOF and optionally SUBFIND 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;
}