-
Notifications
You must be signed in to change notification settings - Fork 12
/
HBT.cpp
99 lines (84 loc) · 2.46 KB
/
HBT.cpp
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
using namespace std;
#include <cstdlib>
#include <iostream>
#include <string>
#include <omp.h>
#include "src/mpi_wrapper.h"
#include "src/datatypes.h"
#include "src/config_parser.h"
#include "src/snapshot.h"
#include "src/halo.h"
#include "src/subhalo.h"
#include "src/mymath.h"
#include "src/particle_exchanger.h"
int main(int argc, char **argv)
{
MPI_Init(&argc, &argv);
MpiWorker_t world(MPI_COMM_WORLD);
#ifdef _OPENMP
//omp_set_nested(0);
omp_set_max_active_levels(1); //max_active_level 0: no para; 1: single layer; >1: nest enabled
#endif
int snapshot_start, snapshot_end;
if(0==world.rank())
{
ParseHBTParams(argc, argv, HBTConfig, snapshot_start, snapshot_end);
mkdir(HBTConfig.SubhaloPath.c_str(), 0755);
HBTConfig.DumpParameters();
cout<<argv[0]<<" run using "<<world.size()<<" mpi tasks";
#ifdef _OPENMP
#pragma omp parallel
#pragma omp master
cout<<", each with "<<omp_get_num_threads()<<" threads";
#endif
cout<<endl;
}
HBTConfig.BroadCast(world, 0, snapshot_start, snapshot_end);
SubhaloSnapshot_t subsnap;
subsnap.Load(world, snapshot_start-1, SubReaderDepth_t::SrcParticles);
Timer_t timer;
ofstream time_log;
if(world.rank()==0)
{
time_log.open(HBTConfig.SubhaloPath+"/timing.log", fstream::out|fstream::app);
time_log<<fixed<<setprecision(1);//<<setw(8);
}
for(int isnap=snapshot_start;isnap<=snapshot_end;isnap++)
{
timer.Tick(world.Communicator);
ParticleSnapshot_t partsnap;
partsnap.Load(world, isnap);
subsnap.SetSnapshotIndex(isnap);
HaloSnapshot_t halosnap;
halosnap.Load(world, isnap);
timer.Tick(world.Communicator);
// cout<<"updating halo particles...\n";
halosnap.UpdateParticles(world, partsnap);
timer.Tick(world.Communicator);
// if(world.rank()==0) cout<<"updateing subsnap particles...\n";
subsnap.UpdateParticles(world, partsnap);
timer.Tick(world.Communicator);
subsnap.AssignHosts(world, halosnap, partsnap);
subsnap.PrepareCentrals(world, halosnap);
timer.Tick(world.Communicator);
if(world.rank()==0) cout<<"unbinding...\n";
subsnap.RefineParticles();
timer.Tick(world.Communicator);
subsnap.MergeSubhalos();
timer.Tick(world.Communicator);
subsnap.UpdateTracks(world, halosnap);
timer.Tick(world.Communicator);
subsnap.Save(world);
timer.Tick(world.Communicator);
if(world.rank()==0)
{
time_log<<isnap;
for(int i=1;i<timer.Size();i++)
time_log<<"\t"<<timer.GetSeconds(i);
time_log<<endl;
}
timer.Reset();
}
MPI_Finalize();
return 0;
}