Skip to content

Commit e3f2a88

Browse files
authored
Merge pull request #241 from ComputationalRadiationPhysics/revert-234-master
Revert "Make filename creation consistent"
2 parents 0b6cb96 + fb8800e commit e3f2a88

13 files changed

+77
-741
lines changed

src/HandleMgr.cpp

Lines changed: 19 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2013-2016 Felix Schmitt, Alexander Grund
2+
* Copyright 2013 Felix Schmitt
33
*
44
* This file is part of libSplash.
55
*
@@ -27,17 +27,17 @@
2727
#include <hdf5.h>
2828

2929
#include "splash/core/HandleMgr.hpp"
30-
#include "splash/core/logging.hpp"
31-
#include "splash/core/DCHelper.hpp"
3230

3331
namespace splash
3432
{
3533

3634
HandleMgr::HandleMgr(uint32_t maxHandles, FileNameScheme fileNameScheme) :
3735
maxHandles(maxHandles),
36+
numHandles(0),
3837
mpiSize(1, 1, 1),
3938
fileNameScheme(fileNameScheme),
4039
fileFlags(0),
40+
singleFile(true),
4141
fileCreateCallback(NULL),
4242
fileCreateUserData(NULL),
4343
fileOpenCallback(NULL),
@@ -69,53 +69,26 @@ namespace splash
6969
return full_msg.str();
7070
}
7171

72-
void HandleMgr::setFileNameScheme(FileNameScheme fileNameScheme) throw (DCException)
73-
{
74-
if (this->fileNameScheme == fileNameScheme)
75-
return;
76-
if (!filename.empty())
77-
throw DCException(getExceptionString("setFileNameScheme",
78-
"Tried to change scheme while file(s) were still open", ""));
79-
this->fileNameScheme = fileNameScheme;
80-
}
81-
8272
void HandleMgr::open(Dimensions mpiSize, const std::string baseFilename,
8373
hid_t fileAccProperties, unsigned flags)
84-
throw (DCException)
8574
{
75+
this->numHandles = mpiSize.getScalarSize();
8676
this->mpiSize.set(mpiSize);
8777
this->filename = baseFilename;
8878
this->fileAccProperties = fileAccProperties;
8979
this->fileFlags = flags;
90-
// Validation: For parallel files we normally append MPI rank or iteration number.
91-
// This is disabled by using FNS_FULLNAME
92-
// or when the filename already contains an h5-extension.
93-
if (fileNameScheme != FNS_FULLNAME && baseFilename.find(".h5") == baseFilename.length() - 3)
94-
{
95-
if (mpiSize.getScalarSize() > 1)
96-
{
97-
throw DCException(getExceptionString("open",
98-
"Passed full filename for parallel file operations",
99-
baseFilename.c_str()));
100-
} else
101-
{
102-
log_msg(1, "\n"
103-
"\tWarning: Passed full filename for parallel file operations: %s\n"
104-
"It is recommended to pass only the base name (no extension)"
105-
"and let the implementation choose a filename.\n", filename.c_str());
106-
}
107-
}
80+
this->singleFile = false;
10881
}
10982

11083
void HandleMgr::open(const std::string fullFilename,
11184
hid_t fileAccProperties, unsigned flags)
112-
throw (DCException)
11385
{
114-
setFileNameScheme(FNS_FULLNAME);
86+
this->numHandles = 1;
11587
this->mpiSize.set(1, 1, 1);
11688
this->filename = fullFilename;
11789
this->fileAccProperties = fileAccProperties;
11890
this->fileFlags = flags;
91+
this->singleFile = true;
11992
}
12093

12194
uint32_t HandleMgr::indexFromPos(Dimensions& mpiPos)
@@ -152,7 +125,7 @@ namespace splash
152125
throw (DCException)
153126
{
154127
uint32_t index = 0;
155-
if (fileNameScheme != FNS_FULLNAME)
128+
if (!singleFile)
156129
index = indexFromPos(mpiPos);
157130

158131
HandleMap::iterator iter = handles.find(index);
@@ -177,34 +150,28 @@ namespace splash
177150
leastAccIndex.ctr = 0;
178151
}
179152

180-
// Append prefix and extension if we don't have a full filename (extension)
181-
std::string fullFilename;
182-
if (fileNameScheme != FNS_FULLNAME && filename.find(".h5") != filename.length() - 3)
153+
std::stringstream filenameStream;
154+
filenameStream << filename;
155+
if (!singleFile)
183156
{
184-
std::stringstream filenameStream;
185-
filenameStream << filename;
186157
if (fileNameScheme == FNS_MPI)
187158
{
188159
filenameStream << "_" << mpiPos[0] << "_" << mpiPos[1] <<
189160
"_" << mpiPos[2] << ".h5";
190-
} else if(fileNameScheme == FNS_ITERATIONS)
161+
} else
191162
filenameStream << "_" << mpiPos[0] << ".h5";
192-
fullFilename = filenameStream.str();
193-
}else
194-
fullFilename = filename;
163+
}
195164

196165
H5Handle newHandle = 0;
197166

198167
// serve requests to create files once as create and as read/write afterwards
199168
if ((fileFlags & H5F_ACC_TRUNC) && (createdFiles.find(index) == createdFiles.end()))
200169
{
201-
DCHelper::testFilename(fullFilename);
202-
203-
newHandle = H5Fcreate(fullFilename.c_str(), fileFlags,
170+
newHandle = H5Fcreate(filenameStream.str().c_str(), fileFlags,
204171
H5P_FILE_CREATE_DEFAULT, fileAccProperties);
205172
if (newHandle < 0)
206173
throw DCException(getExceptionString("get", "Failed to create file",
207-
fullFilename.c_str()));
174+
filenameStream.str().c_str()));
208175

209176
createdFiles.insert(index);
210177

@@ -217,10 +184,10 @@ namespace splash
217184
if (fileFlags & H5F_ACC_TRUNC)
218185
tmp_flags = H5F_ACC_RDWR;
219186

220-
newHandle = H5Fopen(fullFilename.c_str(), tmp_flags, fileAccProperties);
187+
newHandle = H5Fopen(filenameStream.str().c_str(), tmp_flags, fileAccProperties);
221188
if (newHandle < 0)
222189
throw DCException(getExceptionString("get", "Failed to open file",
223-
fullFilename.c_str()));
190+
filenameStream.str().c_str()));
224191

225192
if (fileOpenCallback)
226193
fileOpenCallback(newHandle, index, fileOpenUserData);
@@ -257,6 +224,8 @@ namespace splash
257224
leastAccIndex.ctr = 0;
258225
leastAccIndex.index = 0;
259226
mpiSize.set(1, 1, 1);
227+
numHandles = 0;
228+
singleFile = true;
260229

261230
// close all remaining handles
262231
HandleMap::const_iterator iter = handles.begin();

src/ParallelDataCollector.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2013-2016 Felix Schmitt, Axel Huebl, Alexander Grund
2+
* Copyright 2013-2015 Felix Schmitt, Axel Huebl
33
*
44
* This file is part of libSplash.
55
*
@@ -67,6 +67,14 @@ namespace splash
6767
log_msg(3, "Raw Data Cache (File) = %llu KiB", (long long unsigned) (rawCacheSize / 1024));
6868
}
6969

70+
std::string ParallelDataCollector::getFullFilename(uint32_t id, std::string baseFilename)
71+
{
72+
std::stringstream serial_filename;
73+
serial_filename << baseFilename << "_" << id << ".h5";
74+
75+
return serial_filename.str();
76+
}
77+
7078
std::string ParallelDataCollector::getExceptionString(std::string func, std::string msg,
7179
const char *info)
7280
{
@@ -193,16 +201,15 @@ namespace splash
193201

194202
ParallelDataCollector::~ParallelDataCollector()
195203
{
196-
close();
197204
H5Pclose(fileAccProperties);
198-
finalize();
199205
}
200206

201207
void ParallelDataCollector::finalize()
202208
{
209+
log_msg(1, "finalizing data collector");
210+
203211
if (options.mpiComm != MPI_COMM_NULL)
204212
{
205-
log_msg(1, "finalizing data collector");
206213
MPI_Comm_free(&options.mpiComm);
207214
options.mpiComm = MPI_COMM_NULL;
208215
}
@@ -238,9 +245,6 @@ namespace splash
238245

239246
void ParallelDataCollector::close()
240247
{
241-
if (fileStatus == FST_CLOSED)
242-
return;
243-
244248
log_msg(1, "closing parallel data collector");
245249

246250
// close opened hdf5 file handles

src/SerialDataCollector.cpp

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2013-2016 Felix Schmitt, Axel Huebl, Alexander Grund
2+
* Copyright 2013-2015 Felix Schmitt, Axel Huebl
33
*
44
* This file is part of libSplash.
55
*
@@ -35,6 +35,7 @@
3535
#include "splash/core/DCAttribute.hpp"
3636
#include "splash/core/DCDataSet.hpp"
3737
#include "splash/core/DCGroup.hpp"
38+
#include "splash/core/DCHelper.hpp"
3839
#include "splash/core/SDCHelper.hpp"
3940
#include "splash/core/logging.hpp"
4041
#include "splash/basetypes/basetypes.hpp"
@@ -69,18 +70,8 @@ namespace splash
6970
return (stat(filename.c_str(), &fileInfo) == 0);
7071
}
7172

72-
std::string SerialDataCollector::getFullFilename(const Dimensions mpiPos, std::string baseFilename,
73-
bool isFullNameAllowed) const throw (DCException)
73+
std::string SerialDataCollector::getFullFilename(const Dimensions mpiPos, std::string baseFilename) const
7474
{
75-
// Check for existing extension
76-
if (baseFilename.find(".h5") == baseFilename.length() - 3)
77-
{
78-
if (isFullNameAllowed)
79-
return baseFilename;
80-
else
81-
throw DCException("Full filename is not allowed!");
82-
}
83-
8475
std::stringstream serial_filename;
8576
serial_filename << baseFilename << "_" << mpiPos[0] << "_" << mpiPos[1] <<
8677
"_" << mpiPos[2] << ".h5";
@@ -106,7 +97,7 @@ namespace splash
10697
*******************************************************************************/
10798

10899
SerialDataCollector::SerialDataCollector(uint32_t maxFileHandles) :
109-
handles(maxFileHandles, HandleMgr::FNS_FULLNAME),
100+
handles(maxFileHandles, HandleMgr::FNS_MPI),
110101
fileStatus(FST_CLOSED),
111102
maxID(-1),
112103
mpiTopology(1, 1, 1)
@@ -122,7 +113,7 @@ namespace splash
122113
"failed to initialize/open HDF5 library"));
123114

124115
#ifndef SPLASH_VERBOSE_HDF5
125-
// Suppress automatic output of HDF5 exception messages
116+
// surpress automatic output of HDF5 exception messages
126117
if (H5Eset_auto2(H5E_DEFAULT, NULL, NULL) < 0)
127118
throw DCException(getExceptionString("SerialDataCollector",
128119
"failed to disable error printing"));
@@ -134,7 +125,6 @@ namespace splash
134125

135126
SerialDataCollector::~SerialDataCollector()
136127
{
137-
close();
138128
}
139129

140130
void SerialDataCollector::open(const char* filename, FileCreationAttr &attr)
@@ -167,19 +157,16 @@ namespace splash
167157

168158
void SerialDataCollector::close()
169159
{
170-
if (fileStatus == FST_CLOSED)
171-
return;
172-
173160
log_msg(1, "closing serial data collector");
174161

175-
if ((fileStatus == FST_CREATING || fileStatus == FST_WRITING) &&
176-
maxID >= 0)
162+
if (fileStatus == FST_CREATING || fileStatus == FST_WRITING)
177163
{
164+
DCGroup group;
165+
group.open(handles.get(0), SDC_GROUP_HEADER);
166+
178167
// write number of iterations
179168
try
180169
{
181-
DCGroup group;
182-
group.open(handles.get(0), SDC_GROUP_HEADER);
183170
ColTypeInt32 ctInt32;
184171
DCAttribute::writeAttribute(SDC_ATTR_MAX_ID, ctInt32.getDataType(),
185172
group.getHandle(), &maxID);
@@ -759,8 +746,9 @@ namespace splash
759746
{
760747
this->fileStatus = FST_CREATING;
761748

762-
std::string full_filename = getFullFilename(attr.mpiPosition, filename,
763-
attr.mpiSize.getScalarSize() == 1);
749+
// appends the mpiPosition to the filename (e.g. myfile_0_1_0.h5)
750+
std::string full_filename = getFullFilename(attr.mpiPosition, filename);
751+
DCHelper::testFilename(full_filename);
764752

765753
this->enableCompression = attr.enableCompression;
766754

@@ -791,8 +779,11 @@ namespace splash
791779
{
792780
fileStatus = FST_WRITING;
793781

794-
std::string full_filename = getFullFilename(attr.mpiPosition, filename,
795-
attr.mpiSize.getScalarSize() == 1);
782+
std::string full_filename = filename;
783+
if (full_filename.find(".h5") == std::string::npos)
784+
full_filename = getFullFilename(attr.mpiPosition, filename);
785+
786+
DCHelper::testFilename(full_filename);
796787

797788
this->enableCompression = attr.enableCompression;
798789

@@ -814,7 +805,9 @@ namespace splash
814805
this->fileStatus = FST_MERGING;
815806

816807
// open reference file to get mpi information
817-
std::string full_filename = getFullFilename(Dimensions(0, 0, 0), filename, true);
808+
std::string full_filename = getFullFilename(Dimensions(0, 0, 0), filename);
809+
810+
DCHelper::testFilename(full_filename);
818811

819812
if (!fileExists(full_filename))
820813
{
@@ -828,7 +821,6 @@ namespace splash
828821
// no compression for in-memory datasets
829822
this->enableCompression = false;
830823

831-
handles.setFileNameScheme(HandleMgr::FNS_MPI);
832824
handles.open(mpiTopology, filename, fileAccProperties, H5F_ACC_RDONLY);
833825
}
834826

@@ -837,7 +829,11 @@ namespace splash
837829
{
838830
this->fileStatus = FST_READING;
839831

840-
std::string full_filename = getFullFilename(attr.mpiPosition, filename, true);
832+
std::string full_filename = filename;
833+
if (full_filename.find(".h5") == std::string::npos)
834+
full_filename = getFullFilename(attr.mpiPosition, filename);
835+
836+
DCHelper::testFilename(full_filename);
841837

842838
if (!fileExists(full_filename))
843839
{

src/include/splash/ParallelDataCollector.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ namespace splash
5454
*/
5555
void setFileAccessParams(hid_t& fileAccProperties);
5656

57+
/**
58+
* Constructs a filename from a base filename and the current id
59+
* such as baseFilename+id+.h5
60+
*
61+
* @param id Iteration ID.
62+
* @param baseFilename Base filename for the new file.
63+
* @return newly Constructed filename including file extension.
64+
*/
65+
static std::string getFullFilename(uint32_t id, std::string baseFilename);
66+
5767
/**
5868
* Internal function for formatting exception messages.
5969
*

src/include/splash/SerialDataCollector.hpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,13 @@ namespace splash
6060

6161
/**
6262
* Constructs a filename from a base filename and the process' mpi position
63-
* such as myfile_0_1_0.h5
64-
* Does nothing if the filename already ends with ".h5" (only allowed
65-
* for Prod(mpiSize)==1 or reading).
63+
* such as baseFilename+mpiPos+.h5
6664
*
6765
* @param mpiPos MPI position of the process
6866
* @param baseFilename base filename for the new file
69-
* @param isFullNameAllowed If false, an exception is raised when a full name is passed
70-
* @return newly constructed filename including file extension
67+
* @return newly constructed filename iucluding file exitension
7168
*/
72-
std::string getFullFilename(const Dimensions mpiPos, std::string baseFilename,
73-
bool isFullNameAllowed) const throw (DCException);
69+
std::string getFullFilename(const Dimensions mpiPos, std::string baseFilename) const;
7470

7571
/**
7672
* Internal function for formatting exception messages.

0 commit comments

Comments
 (0)