-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
74 lines (63 loc) · 2.15 KB
/
main.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
#include <mpi.h>
#include <array>
#include <exception>
#include <iomanip> // std::setw, std::setfill
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#ifdef WIN32
#include <direct.h> // Windows
#else
#include <sys/stat.h>
#include <sys/types.h>
#endif
#include "SpatialGMM.hpp"
#include "utils.h"
std::string to_string_with_leading_zeros(int value, int width) {
std::ostringstream stream;
stream << std::internal << std::setfill('0') << std::setw(width) << value;
return stream.str();
}
int main(int argc, char** argv) {
MPI_Init(NULL, NULL);
int timestep[2] = {1, 10};
int dt = 1;
if (argc != 2) {
std::cout << "Usage: " << argv[0] << " <DatasetDir>" << std::endl;
return 1;
}
std::string variableName = "Pf";
std::string datasetName = "Isabel";
std::string datasetDir = argv[1];
Configuration config;
config.setDataPath(datasetDir + datasetName + "/" + variableName + "/");
config.setDimensions(500, 500, 100);
config.setBlockSize(32); // the resolution of each SGMM block
config.setVariableName(variableName);
std::string parameterPath = datasetDir + datasetName + "/";
std::string extensionName = ".bin";
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
for (int i = timestep[0]; i < timestep[1]; i++) {
config.setRawDataFilename(
variableName + to_string_with_leading_zeros(i * dt, 2) + extensionName);
// building statistical representation of the 3D volume
SpatialGMM::Representation<float> result = SpatialGMM::DataModeling<float>(
config.getDimensions(), config.getBlockSize(),
config.getDataPath() + config.getRawDataFilename(), Endian::Big());
SpatialGMM::ExportReconstructedVolume<float>(
config.getDataPath() + "output.raw", result, config.getDimensions(),
config.getBlockSize());
std::string folder = parameterPath + "Params/" + variableName +
to_string_with_leading_zeros(i * dt, 2) + "/";
#ifdef WIN32
mkdir(folder.c_str());
#else
mkdir(folder.c_str(), 0755);
#endif
SpatialGMM::SaveParameters<float>(
folder + "params_" + std::to_string(rank) + ".json", result);
}
MPI_Finalize();
}