Attached Files | vtkExodusIIReader.cxx.diff [^] (6,856 bytes) 2015-07-06 21:28 [Show Content] [Hide Content]diff --git a/IO/Exodus/vtkExodusIIReader.cxx b/IO/Exodus/vtkExodusIIReader.cxx
index d7d8237..3e9b385 100644
--- a/IO/Exodus/vtkExodusIIReader.cxx
+++ b/IO/Exodus/vtkExodusIIReader.cxx
@@ -1434,8 +1434,14 @@ void vtkExodusIIReaderPrivate::AddPointArray(
dest->SetName( src->GetName() );
dest->SetNumberOfComponents( src->GetNumberOfComponents() );
dest->SetNumberOfTuples( bsinfop->NextSqueezePoint );
- std::map<vtkIdType,vtkIdType>::iterator it;
- for ( it = bsinfop->PointMap.begin(); it != bsinfop->PointMap.end(); ++ it )
+ std::map<vtkIdType,vtkIdType>::iterator it, itEnd;
+ //
+ // I moved the end condition of the loop out of the for(;;) loop.
+ // Assuming it doesn't change within the loop itself!
+ // The reason is that the code was making the call every loop.
+ //
+ itEnd = bsinfop->PointMap.end();
+ for ( it = bsinfop->PointMap.begin(); it != itEnd; ++ it )
{
pd->CopyTuple( src, dest, it->first, it->second );
}
@@ -1719,13 +1725,31 @@ vtkDataArray* vtkExodusIIReaderPrivate::GetCacheOrRead( vtkExodusIICacheKey key
std::vector<double> tmpTuple;
tmpTuple.resize( ncomps );
tmpTuple[ncomps - 1] = 0.; // In case we're embedding a 2-D vector in 3-D
- for ( t = 0; t < arr->GetNumberOfTuples(); ++t )
+
+ //
+ // Lets unroll the most common case - components == 3.
+ //
+ if ( ainfop->Components == 3)
{
- for ( c = 0; c < ainfop->Components; ++c )
+ int maxTuples = arr->GetNumberOfTuples();
+ for ( t = 0; t < maxTuples; ++t )
{
- tmpTuple[c] = tmpVal[c][t];
+ tmpTuple[0] = tmpVal[0][t];
+ tmpTuple[1] = tmpVal[1][t];
+ tmpTuple[2] = tmpVal[2][t];
+ arr->SetTuple( t, &tmpTuple[0] );
+ }
+ }
+ else
+ {
+ for ( t = 0; t < arr->GetNumberOfTuples(); ++t )
+ {
+ for ( c = 0; c < ainfop->Components; ++c )
+ {
+ tmpTuple[c] = tmpVal[c][t];
+ }
+ arr->SetTuple( t, &tmpTuple[0] );
}
- arr->SetTuple( t, &tmpTuple[0] );
}
}
}
@@ -2002,7 +2026,11 @@ vtkDataArray* vtkExodusIIReaderPrivate::GetCacheOrRead( vtkExodusIICacheKey key
arr = 0;
return 0;
}
- for ( vtkIdType i = 0; i < arr->GetNumberOfTuples(); ++i )
+ //
+ // Move the check of maxTuples out of the for(;;) loop.
+ //
+ vtkIdType maxTuples = arr->GetNumberOfTuples();
+ for ( vtkIdType i = 0; i < maxTuples; ++i )
{
iarr->SetValue( i, tmpMap[i] );
}
@@ -2279,7 +2307,11 @@ vtkDataArray* vtkExodusIIReaderPrivate::GetCacheOrRead( vtkExodusIICacheKey key
}
else
{
- for ( vtkIdType i = 0; i < iarr->GetNumberOfTuples(); ++i )
+ //
+ // Move getting the maxTuples from the for(;;) loop.
+ //
+ vtkIdType maxTuples = iarr->GetNumberOfTuples();
+ for ( vtkIdType i = 0; i < maxTuples ; ++i )
{
iarr->SetValue( i, tmpMap[i] );
}
@@ -2647,7 +2679,24 @@ vtkDataArray* vtkExodusIIReaderPrivate::GetCacheOrRead( vtkExodusIICacheKey key
break;
}
double* cptr = darr->GetPointer( c );
- for ( t = 0; t < this->ModelParameters.num_nodes; ++t )
+
+ //
+ // num_nodes can get big. Lets unroll the loop
+ //
+ for ( t = 0; t+8 < this->ModelParameters.num_nodes; t+=8 )
+ {
+ *(cptr+3*0) = coordTmp[t+0];
+ *(cptr+3*1) = coordTmp[t+1];
+ *(cptr+3*2) = coordTmp[t+2];
+ *(cptr+3*3) = coordTmp[t+3];
+ *(cptr+3*4) = coordTmp[t+4];
+ *(cptr+3*5) = coordTmp[t+5];
+ *(cptr+3*6) = coordTmp[t+6];
+ *(cptr+3*7) = coordTmp[t+7];
+ cptr += 3*8;
+ }
+
+ for ( ; t < this->ModelParameters.num_nodes; ++t )
{
*cptr = coordTmp[t];
cptr += 3;
@@ -2661,29 +2710,66 @@ vtkDataArray* vtkExodusIIReaderPrivate::GetCacheOrRead( vtkExodusIICacheKey key
*cptr = 0.;
}
}
+ //
+ // Unrolling some of the inner loops for the most common case - dim 3.
+ // Also moving the maxTuples from inside of the for(;;) loops
+ // Also moving cos() calculations out of the bottom of loops.
+ //
if ( displ )
{
double* coords = darr->GetPointer( 0 );
if ( this->HasModeShapes && this->AnimateModeShapes )
{
- for ( vtkIdType idx = 0; idx < displ->GetNumberOfTuples(); ++idx )
+ double tempDouble = this->DisplacementMagnitude * cos(2.0 * vtkMath::Pi() * this->ModeShapeTime);
+ if ( dim == 3)
{
- double* dispVal = displ->GetTuple( idx );
- for ( c = 0; c < dim; ++c )
- coords[c] += dispVal[c] * this->DisplacementMagnitude * cos( 2. * vtkMath::Pi() * this->ModeShapeTime );
-
- coords += 3;
+ vtkIdType maxTuples = arr->GetNumberOfTuples();
+ for ( vtkIdType idx = 0; idx < maxTuples; ++idx )
+ {
+ double* dispVal = displ->GetTuple( idx );
+ coords[0] += dispVal[0] * tempDouble;
+ coords[1] += dispVal[1] * tempDouble;
+ coords[2] += dispVal[2] * tempDouble;
+ coords += 3;
+ }
+ }
+ else
+ {
+ for ( vtkIdType idx = 0; idx < displ->GetNumberOfTuples(); ++idx )
+ {
+ double* dispVal = displ->GetTuple( idx );
+ for ( c = 0; c < dim; ++c )
+ coords[c] += dispVal[c] * tempDouble;
+
+ coords += 3;
+ }
}
}
else
{
- for ( vtkIdType idx = 0; idx < displ->GetNumberOfTuples(); ++idx )
+ if ( dim == 3)
{
- double* dispVal = displ->GetTuple( idx );
- for ( c = 0; c < dim; ++c )
- coords[c] += dispVal[c] * this->DisplacementMagnitude;
-
- coords += 3;
+ vtkIdType maxTuples = arr->GetNumberOfTuples();
+ for ( vtkIdType idx = 0; idx < maxTuples; ++idx )
+ {
+ double* dispVal = displ->GetTuple( idx );
+ coords[0] += dispVal[0] * this->DisplacementMagnitude;
+ coords[1] += dispVal[1] * this->DisplacementMagnitude;
+ coords[2] += dispVal[2] * this->DisplacementMagnitude;
+
+ coords += 3;
+ }
+ }
+ else
+ {
+ for ( vtkIdType idx = 0; idx < displ->GetNumberOfTuples(); ++idx )
+ {
+ double* dispVal = displ->GetTuple( idx );
+ for ( c = 0; c < dim; ++c )
+ coords[c] += dispVal[c] * this->DisplacementMagnitude;
+
+ coords += 3;
+ }
}
}
}
vtkDataArrayTemplate.txx.diff [^] (4,659 bytes) 2015-07-06 21:37 [Show Content] [Hide Content]diff --git a/Common/Core/vtkDataArrayTemplate.txx b/Common/Core/vtkDataArrayTemplate.txx
index dbf8402..a44c0a1 100644
--- a/Common/Core/vtkDataArrayTemplate.txx
+++ b/Common/Core/vtkDataArrayTemplate.txx
@@ -629,10 +629,22 @@ double* vtkDataArrayTemplate<T>::GetTuple(vtkIdType i)
}
// Copy the data into the tuple.
+ //
+ // Unrolling loop, assuming the main case is three components.
+ //
T* t = this->Array + this->NumberOfComponents*i;
- for(int j=0; j < this->NumberOfComponents; ++j)
+ if ( this->NumberOfComponents == 3)
{
- this->Tuple[j] = static_cast<double>(t[j]);
+ this->Tuple[0] = static_cast<double>(t[0]);
+ this->Tuple[1] = static_cast<double>(t[1]);
+ this->Tuple[2] = static_cast<double>(t[2]);
+ }
+ else
+ {
+ for(int j=0; j < this->NumberOfComponents; ++j)
+ {
+ this->Tuple[j] = static_cast<double>(t[j]);
+ }
}
return this->Tuple;
#else
@@ -675,58 +687,117 @@ double* vtkDataArrayTemplate<T>::GetTuple(vtkIdType i)
//----------------------------------------------------------------------------
// Copy the tuple value into a user-provided array.
+//
+// Most of the time there is only one component. Optimize for this case.
+//
template <class T>
void vtkDataArrayTemplate<T>::GetTuple(vtkIdType i, double* tuple)
{
- T* t = this->Array + this->NumberOfComponents*i;
- for(int j=0; j < this->NumberOfComponents; ++j)
+ if ( this->NumberOfComponents == 1 )
{
- tuple[j] = static_cast<double>(t[j]);
+ T* t = this->Array + i;
+ tuple[0] = static_cast<double>(t[0]);
+ }
+ else
+ {
+ T* t = this->Array + this->NumberOfComponents*i;
+ for(int j=0; j < this->NumberOfComponents; ++j)
+ {
+ tuple[j] = static_cast<double>(t[j]);
+ }
}
}
//----------------------------------------------------------------------------
+//
+// Most of the time there is only one component. Optimize for this case.
+//
template <class T>
void vtkDataArrayTemplate<T>::GetTupleValue(vtkIdType i, T* tuple)
{
- T* t = this->Array + this->NumberOfComponents*i;
- for(int j=0; j < this->NumberOfComponents; ++j)
+ if ( this->NumberOfComponents == 1 )
{
- tuple[j] = t[j];
+ T* t = this->Array + i;
+ tuple[0] = t[0];
+ }
+ else
+ {
+ T* t = this->Array + this->NumberOfComponents*i;
+ for(int j=0; j < this->NumberOfComponents; ++j)
+ {
+ tuple[j] = t[j];
+ }
}
}
//----------------------------------------------------------------------------
// Set the tuple value at the ith location in the array.
+//
+// Unrolling loop, assuming the main case is three components.
+//
template <class T>
void vtkDataArrayTemplate<T>::SetTuple(vtkIdType i, const float* tuple)
{
vtkIdType loc = i * this->NumberOfComponents;
- for(int j=0; j < this->NumberOfComponents; ++j)
+ if ( this->NumberOfComponents == 3 )
+ {
+ this->Array[loc+0] = static_cast<T>(tuple[0]);
+ this->Array[loc+1] = static_cast<T>(tuple[1]);
+ this->Array[loc+2] = static_cast<T>(tuple[2]);
+ }
+ else
{
- this->Array[loc+j] = static_cast<T>(tuple[j]);
+ for(int j=0; j < this->NumberOfComponents; ++j)
+ {
+ this->Array[loc+j] = static_cast<T>(tuple[j]);
+ }
}
this->DataChanged();
}
-
+
+//
+// Unrolling loop, assuming the main case is three components.
+//
template <class T>
void vtkDataArrayTemplate<T>::SetTuple(vtkIdType i, const double* tuple)
{
vtkIdType loc = i * this->NumberOfComponents;
- for(int j=0; j < this->NumberOfComponents; ++j)
+ if ( this->NumberOfComponents == 3 )
{
- this->Array[loc+j] = static_cast<T>(tuple[j]);
+ this->Array[loc+0] = static_cast<T>(tuple[0]);
+ this->Array[loc+1] = static_cast<T>(tuple[1]);
+ this->Array[loc+2] = static_cast<T>(tuple[2]);
+ }
+ else
+ {
+ for(int j=0; j < this->NumberOfComponents; ++j)
+ {
+ this->Array[loc+j] = static_cast<T>(tuple[j]);
+ }
}
+
this->DataChanged();
}
+//
+// Unrolling loop, assuming the main case is three components.
+//
template <class T>
void vtkDataArrayTemplate<T>::SetTupleValue(vtkIdType i, const T* tuple)
{
vtkIdType loc = i * this->NumberOfComponents;
- for(int j=0; j < this->NumberOfComponents; ++j)
+ if ( this->NumberOfComponents == 3 )
{
- this->Array[loc+j] = tuple[j];
+ this->Array[loc+0] = tuple[0];
+ this->Array[loc+1] = tuple[1];
+ this->Array[loc+2] = tuple[2];
+ }
+ else
+ {
+ for(int j=0; j < this->NumberOfComponents; ++j)
+ {
+ this->Array[loc+j] = tuple[j];
+ }
}
this->DataChanged();
}
Unoptimized.png [^] (999,013 bytes) 2015-07-06 21:37
Optimized.png [^] (987,162 bytes) 2015-07-06 21:37 |