Commit 177f37d8 authored by Andrew Bauer's avatar Andrew Bauer

Padding filenames for ExodusII writer based on number of processes

In order to read in ExodusII files written out in parallel we
need to pad the process ids with zeros so that all of them are
associated together.
parent f2c5945d
Pipeline #33152 passed with stage
...@@ -49,12 +49,23 @@ ...@@ -49,12 +49,23 @@
#include <cctype> #include <cctype>
#include <map> #include <map>
#include <ctime> #include <ctime>
#include <sstream>
vtkObjectFactoryNewMacro (vtkExodusIIWriter); vtkObjectFactoryNewMacro (vtkExodusIIWriter);
vtkCxxSetObjectMacro (vtkExodusIIWriter, ModelMetadata, vtkModelMetadata); vtkCxxSetObjectMacro (vtkExodusIIWriter, ModelMetadata, vtkModelMetadata);
namespace
{
unsigned int GetNumberOfDigits(unsigned int i)
{
if (i<10)
{
return 1;
}
return GetNumberOfDigits(i/10)+1;
}
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
vtkExodusIIWriter::vtkExodusIIWriter () vtkExodusIIWriter::vtkExodusIIWriter ()
...@@ -595,24 +606,25 @@ int vtkExodusIIWriter::CreateNewExodusFile() ...@@ -595,24 +606,25 @@ int vtkExodusIIWriter::CreateNewExodusFile()
} }
else else
{ {
char *myFileName = new char [VTK_MAXPATH]; std::ostringstream myFileName;
if (this->CurrentTimeIndex == 0) myFileName << this->FileName << ".";
{ if (this->CurrentTimeIndex != 0)
sprintf(myFileName, "%s.%d.%d", this->FileName, this->NumberOfProcesses, this->MyRank);
}
else
{ {
sprintf(myFileName, "%s_%06d.%d.%d", myFileName << "_" << std::setfill('0') << std::setw(6) <<
this->FileName, this->CurrentTimeIndex, this->NumberOfProcesses, this->MyRank); this->CurrentTimeIndex << std::setw(0) << ".";
} }
this->fid = ex_create(myFileName, EX_CLOBBER, &compWordSize, &IOWordSize); unsigned int numDigits = GetNumberOfDigits(
static_cast<unsigned int>(this->NumberOfProcesses-1));
myFileName << this->NumberOfProcesses << "." << std::setfill('0')
<< std::setw(numDigits) << this->MyRank;
this->fid = ex_create(myFileName.str().c_str(), EX_CLOBBER,
&compWordSize, &IOWordSize);
if (fid <= 0) if (fid <= 0)
{ {
vtkErrorMacro ( vtkErrorMacro (
<< "vtkExodusIIWriter: CreateNewExodusFile can't create " << "vtkExodusIIWriter: CreateNewExodusFile can't create "
<< myFileName); << myFileName.str());
} }
delete [] myFileName;
} }
// FileTimeOffset makes the time in the file relative // FileTimeOffset makes the time in the file relative
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment