[MOAB-dev] r1861 - MOAB/trunk
kraftche at mcs.anl.gov
kraftche at mcs.anl.gov
Thu May 29 11:11:59 CDT 2008
Author: kraftche
Date: 2008-05-29 11:11:59 -0500 (Thu, 29 May 2008)
New Revision: 1861
Modified:
MOAB/trunk/MBCore.cpp
MOAB/trunk/SequenceManager.hpp
MOAB/trunk/TypeSequenceManager.hpp
Log:
Optimize MBCore::get_coords( handle_array, ... ) for case where
handles in array are roughly grouped by entity sequence (the
common case being that they're all in the same sequence.)
This only decreases kD-tree build time by about 5%, but it's still
a good optimization.
Modified: MOAB/trunk/MBCore.cpp
===================================================================
--- MOAB/trunk/MBCore.cpp 2008-05-29 14:40:47 UTC (rev 1860)
+++ MOAB/trunk/MBCore.cpp 2008-05-29 16:11:59 UTC (rev 1861)
@@ -668,22 +668,30 @@
const int num_entities,
double *coords) const
{
- MBErrorCode status;
const EntitySequence* seq;
+ const VertexSequence* vseq;
const MBEntityHandle* const end = entities + num_entities;
-
- for(const MBEntityHandle* iter = entities; iter != end; ++iter)
- {
- if(TYPE_FROM_HANDLE(*iter) != MBVERTEX)
- return MB_TYPE_OUT_OF_RANGE;
-
- status = sequence_manager()->find(*iter, seq);
- if(status != MB_SUCCESS )
- return MB_ENTITY_NOT_FOUND;
+ const MBEntityHandle* iter = entities;
+
+ seq = sequence_manager()->get_last_accessed_sequence( MBVERTEX );
+ if (!seq) // no vertices
+ return num_entities ? MB_ENTITY_NOT_FOUND : MB_SUCCESS;
+ vseq = static_cast<const VertexSequence*>(seq);
+
+ while (iter != end) {
+ if (vseq->start_handle() > *iter || vseq->end_handle() < *iter) {
+ if (TYPE_FROM_HANDLE(*iter) != MBVERTEX)
+ return MB_TYPE_OUT_OF_RANGE;
+
+ if (MB_SUCCESS != sequence_manager()->find(*iter, seq))
+ return MB_ENTITY_NOT_FOUND;
+ vseq = static_cast<const VertexSequence*>(seq);
+ }
- static_cast<const VertexSequence*>(seq)->get_coordinates(*iter, coords);
+ vseq->get_coordinates( *iter, coords );
coords += 3;
- }
+ ++iter;
+ }
return MB_SUCCESS;
}
Modified: MOAB/trunk/SequenceManager.hpp
===================================================================
--- MOAB/trunk/SequenceManager.hpp 2008-05-29 14:40:47 UTC (rev 1860)
+++ MOAB/trunk/SequenceManager.hpp 2008-05-29 16:11:59 UTC (rev 1861)
@@ -44,6 +44,10 @@
/** Count entities of a given MBEntityType */
MBEntityID get_number_entities( MBEntityType type ) const
{ return typeData[type].get_number_entities(); }
+
+ /** Get most recently accessed sequence for a given type */
+ const EntitySequence* get_last_accessed_sequence( MBEntityType type ) const
+ { return typeData[type].get_last_accessed(); }
/**\brief Replace subset of existing sequence with new
* sequence (splits existing sequence)
Modified: MOAB/trunk/TypeSequenceManager.hpp
===================================================================
--- MOAB/trunk/TypeSequenceManager.hpp 2008-05-29 14:40:47 UTC (rev 1860)
+++ MOAB/trunk/TypeSequenceManager.hpp 2008-05-29 16:11:59 UTC (rev 1861)
@@ -176,6 +176,7 @@
inline EntitySequence* find( MBEntityHandle h );
inline MBErrorCode find( MBEntityHandle h, EntitySequence*& );
inline MBErrorCode find( MBEntityHandle h, const EntitySequence*& ) const;
+ inline const EntitySequence* get_last_accessed() const;
/**\brief Get handles for all entities in all sequences. */
inline void get_entities( MBRange& entities_out ) const;
@@ -409,7 +410,10 @@
}
}
}
-
+
+inline const EntitySequence* TypeSequenceManager::get_last_accessed() const
+ { return lastReferenced; /* only NULL if TypeSequenceManager is empty */ }
+
inline void TypeSequenceManager::get_entities( MBRange& entities_out ) const
{
MBRange::iterator in = entities_out.begin();
More information about the moab-dev
mailing list