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
|
/////////////////////////////////////////////////////////////
// //
// Copyright (c) 2003-2014 by The University of Queensland //
// Centre for Geoscience Computing //
// http://earth.uq.edu.au/centre-geoscience-computing //
// //
// Primary Business: Brisbane, Queensland, Australia //
// Licensed under the Open Software License version 3.0 //
// http://www.opensource.org/licenses/osl-3.0.php //
// //
/////////////////////////////////////////////////////////////
#include "Parallel/CheckPointer.h"
#include "Parallel/CheckPointParams.h"
#include "Parallel/CheckPointable.h"
#include "Parallel/mpivbuf.h"
#include "Parallel/mpibarrier.h"
#include "Foundation/console.h"
//--- TML includes ---
#include "tml/comm/comm.h"
#include <fstream>
#include <sstream>
using esys::lsm::CheckPointable;
CheckPointer::CheckPointer(CheckPointable &checkPointable, MPI_Comm mpiComm)
: m_pCheckPointable(&checkPointable),
m_mpiComm(mpiComm)
{
}
CheckPointer::~CheckPointer()
{
}
MPI_Comm CheckPointer::getMpiComm() const
{
return m_mpiComm;
}
void CheckPointer::setMpiComm(MPI_Comm mpiComm)
{
m_mpiComm = mpiComm;
}
void CheckPointer::saveRestartable()
{
CVarMPIBuffer buffer(getMpiComm());
// get check-point parameters
buffer.receiveBroadcast(0);
CheckPointParams checkPointParams = CheckPointParams::unpackFrom(&buffer, getMpiComm());
// Write the check-point info to file.
std::ofstream oStream(checkPointParams.getFileName().c_str());
// set output precision
console.Debug() << "output precision: " << checkPointParams.getPrecision() << "\n";
oStream.precision(checkPointParams.getPrecision());
m_pCheckPointable->saveCheckPointData(oStream);
oStream.close();
}
void CheckPointer::saveDump()
{
CVarMPIBuffer buffer(getMpiComm());
// get check-point parameters
buffer.receiveBroadcast(0);
CheckPointParams checkPointParams = CheckPointParams::unpackFrom(&buffer, getMpiComm());
// Write the check-point info to file.
std::ofstream oStream(checkPointParams.getFileName().c_str());
m_pCheckPointable->saveSnapShotData(oStream);
oStream.close();
}
void CheckPointer::saveThroughMaster(TML_Comm& comm)
{
CVarMPIBuffer buffer(getMpiComm());
CMPIBarrier barrier(getMpiComm());
console.Debug() << "CheckPointer::saveThroughMaster" << "\n";
// get check-point parameters
buffer.receiveBroadcast(0);
CheckPointParams checkPointParams = CheckPointParams::unpackFrom(&buffer, getMpiComm());
// Write the check-point info to string stream.
std::ostringstream oStream;
save(oStream);
console.Debug() << "string length : " << oStream.str().size() << "\n";
string str_data=oStream.str();
barrier.wait("CheckPoint_1");
comm.send_gather(str_data,0);
}
void CheckPointer::loadCheckPoint()
{
CVarMPIBuffer buffer(getMpiComm());
// get check-point parameters
buffer.receiveBroadcast(0);
CheckPointParams checkPointParams = CheckPointParams::unpackFrom(&buffer, getMpiComm());
// Write the check-point info to file.
std::ifstream iStream(checkPointParams.getFileName().c_str());
m_pCheckPointable->loadCheckPointData(iStream);
iStream.close();
}
void CheckPointer::save(std::ostream &oStream)
{
m_pCheckPointable->saveCheckPointData(oStream);
}
|