[MOAB-dev] r1381 - MOAB/trunk
kraftche at mcs.anl.gov
kraftche at mcs.anl.gov
Mon Nov 12 15:17:17 CST 2007
Author: kraftche
Date: 2007-11-12 15:17:17 -0600 (Mon, 12 Nov 2007)
New Revision: 1381
Modified:
MOAB/trunk/AEntityFactory.cpp
MOAB/trunk/AEntityFactory.hpp
MOAB/trunk/SequenceData.hpp
MOAB/trunk/SequenceManager.hpp
MOAB/trunk/TypeSequenceManager.cpp
MOAB/trunk/TypeSequenceManager.hpp
Log:
Store adjacency data on entity sequences
Modified: MOAB/trunk/AEntityFactory.cpp
===================================================================
--- MOAB/trunk/AEntityFactory.cpp 2007-11-12 20:57:20 UTC (rev 1380)
+++ MOAB/trunk/AEntityFactory.cpp 2007-11-12 21:17:17 UTC (rev 1381)
@@ -17,11 +17,15 @@
#include "AEntityFactory.hpp"
#include "MBInternals.hpp"
-#include "MBInterface.hpp"
+#include "MBCore.hpp"
#include "MBRange.hpp"
#include "MBError.hpp"
#include "MBCN.hpp"
#include "MeshTopoUtil.hpp"
+#include "EntitySequence.hpp"
+#include "SequenceData.hpp"
+#include "SequenceManager.hpp"
+#include "MBRangeSeqIntersectIter.hpp"
#include <assert.h>
#include <algorithm>
@@ -29,8 +33,7 @@
-AEntityFactory::AEntityFactory(MBInterface *mdb)
-: mDensePageGroup(sizeof(void*), 0)
+AEntityFactory::AEntityFactory(MBCore *mdb)
{
assert(NULL != mdb);
thisMB = mdb;
@@ -41,31 +44,23 @@
AEntityFactory::~AEntityFactory()
{
// clean up all the adjacency information that was created
- MBRange entities;
MBEntityType ent_type;
// iterate through each element type
- for (ent_type = MBVERTEX; ent_type != MBENTITYSET; ent_type++)
- {
- // clear out entities
- entities.clear();
-
- // get all entities that might have adjacency information on it
- MBErrorCode result = mDensePageGroup.get_entities( ent_type, entities);
- if (result != MB_SUCCESS)
- continue; // if this fails give up.
-
- // iterate through each entity
- MBRange::iterator iter;
- MBAdjacencyVector *adj_vector = 0;
- for(iter = entities.begin(); iter != entities.end(); ++iter)
- {
- adj_vector = NULL;
- result = mDensePageGroup.get_data(*iter, &adj_vector);
- if(result == MB_SUCCESS)
- delete adj_vector;
+ for (ent_type = MBVERTEX; ent_type != MBENTITYSET; ent_type++) {
+ TypeSequenceManager::iterator i;
+ TypeSequenceManager& seqman = thisMB->sequence_manager()->entity_map( ent_type );
+ for (i = seqman.begin(); i != seqman.end(); ++i) {
+ std::vector<MBEntityHandle>** adj_list = (*i)->data()->get_adjacency_data();
+ if (!adj_list)
+ continue;
+ adj_list += (*i)->start_handle() - (*i)->data()->start_handle();
+
+ for (MBEntityID j = 0; j < (*i)->size(); ++j) {
+ delete adj_list[j];
+ adj_list[j] = 0;
+ }
}
-
}
}
@@ -149,22 +144,19 @@
if(!target_entities.empty())
target_entities.clear();
- MBAdjacencyVector *adj_vec = NULL;
- result = mDensePageGroup.get_data(source_entity, &adj_vec);
- // this might return a non-success result, in cases where the adjacencies tag
- // hasn't been created/allocated yet; that's ok, just means there aren't any
- // adj meshsets
- if(result == MB_TAG_NOT_FOUND || adj_vec == NULL)
- return MB_SUCCESS;
- else if (result != MB_SUCCESS) return result;
+ const MBEntityHandle* adj_vec;
+ int num_adj;
+ result = get_adjacencies( source_entity, adj_vec, num_adj );
+ if(result != MB_SUCCESS || adj_vec == NULL)
+ return result;
// find the meshsets in this vector
MBDimensionPair dim_pair = MBCN::TypeDimensionMap[4];
int dum;
- MBAdjacencyVector::iterator start_ent =
- std::lower_bound(adj_vec->begin(), adj_vec->end(), CREATE_HANDLE(dim_pair.first, MB_START_ID, dum));
- MBAdjacencyVector::iterator end_ent =
- std::lower_bound(start_ent, adj_vec->end(), CREATE_HANDLE(dim_pair.second, MB_END_ID, dum));
+ const MBEntityHandle* start_ent =
+ std::lower_bound(adj_vec, adj_vec+num_adj, CREATE_HANDLE(dim_pair.first, MB_START_ID, dum));
+ const MBEntityHandle* end_ent =
+ std::lower_bound(start_ent, adj_vec+num_adj, CREATE_HANDLE(dim_pair.second, MB_END_ID, dum));
// copy the the meshsets
target_entities.resize(end_ent - start_ent);
@@ -193,7 +185,7 @@
// look over nodes to see if this entity already exists
target_entity = 0;
MBErrorCode result;
- std::vector<MBEntityHandle>::iterator i_adj, end_adj;
+ const MBEntityHandle *i_adj, *end_adj;
target_entity = 0;
@@ -202,15 +194,12 @@
create_vert_elem_adjacencies();
// get the adjacency list
- MBAdjacencyVector *adj_vec = NULL;
- result = mDensePageGroup.get_data(vertex_list[0], &adj_vec);
-
- if (MB_SUCCESS != result)
+ const MBEntityHandle* adj_vec;
+ int num_adj;
+ result = get_adjacencies( vertex_list[0], adj_vec, num_adj );
+ if(result != MB_SUCCESS || adj_vec == NULL)
return result;
- if(adj_vec == NULL)
- return result;
-
// check to see if any of these are equivalent to the vertex list
int dum;
@@ -218,8 +207,8 @@
MBEntityHandle temp_vec[15];
int temp_vec_size = 0;
- i_adj = std::lower_bound(adj_vec->begin(), adj_vec->end(), CREATE_HANDLE(target_type, MB_START_ID, dum));
- end_adj = std::lower_bound(i_adj, adj_vec->end(), CREATE_HANDLE(target_type, MB_END_ID, dum));
+ i_adj = std::lower_bound(adj_vec, adj_vec+num_adj, CREATE_HANDLE(target_type, MB_START_ID, dum));
+ end_adj = std::lower_bound(i_adj, adj_vec+num_adj, CREATE_HANDLE(target_type, MB_END_ID, dum));
for (; i_adj != end_adj; ++i_adj)
{
if (TYPE_FROM_HANDLE(*i_adj) != target_type) continue;
@@ -377,18 +366,13 @@
if (to_type == MBVERTEX)
return MB_ALREADY_ALLOCATED;
+
+
MBAdjacencyVector *adj_list_ptr = NULL;
- MBErrorCode result = mDensePageGroup.get_data(from_ent, &adj_list_ptr);
+ MBErrorCode result = get_adjacencies( from_ent, adj_list_ptr, true );
+ if (MB_SUCCESS != result)
+ return result;
- if (NULL == adj_list_ptr)
- {
- // need to make a new adjacency list first
- adj_list_ptr = new MBAdjacencyVector();
- result = mDensePageGroup.set_data(from_ent, &adj_list_ptr);
-
- if (MB_SUCCESS != result) return result;
- }
-
// get an iterator to the right spot in this sorted vector
MBAdjacencyVector::iterator adj_iter;
if (!adj_list_ptr->empty())
@@ -422,26 +406,14 @@
// get the adjacency tag
MBAdjacencyVector *adj_list = NULL;
-
- // get the adjacency data list
- result = mDensePageGroup.get_data(base_entity, &adj_list);
-
- // workaround - if a dense page hasn't been allocated, it won't have an adjacency tag,
- // even if that tag was assigned a default value; just return success for now
- if (result == MB_TAG_NOT_FOUND)
- return MB_SUCCESS;
- else if (adj_list == NULL || MB_SUCCESS != result)
+ result = get_adjacencies( base_entity, adj_list );
+ if (adj_list == NULL || MB_SUCCESS != result)
return result;
// remove the specified entity from the adjacency list and truncate
// the list to the new length
adj_list->erase(std::remove(adj_list->begin(), adj_list->end(), adj_to_remove),
adj_list->end());
-
- // reset the adjacency data list
- //result = thisMB->tag_set_data(adj_tag, base_entity, &adj_list);
- //if (result != MB_SUCCESS)
- //return result;
return result;
}
@@ -490,10 +462,8 @@
// get the adjacency tag
MBAdjacencyVector *adj_list = 0;
- result = mDensePageGroup.get_data(base_entity, &adj_list);
- if (MB_TAG_NOT_FOUND == result || !adj_list)
- return MB_SUCCESS;
- if (MB_SUCCESS != result)
+ result = get_adjacencies( base_entity, adj_list );
+ if (MB_SUCCESS != result || !adj_list)
return result;
@@ -503,10 +473,7 @@
adj_list->clear();
if (delete_adj_list) {
- MBAdjacencyVector* const null_ptr = 0;
- result = mDensePageGroup.set_data( base_entity, &null_ptr );
- if (MB_SUCCESS != result)
- return result;
+ result = set_adjacency_ptr( base_entity, NULL );
delete adj_list;
}
@@ -577,33 +544,47 @@
const MBEntityHandle *&adjacent_entities,
int &num_entities) const
{
- MBAdjacencyVector *adj_vec = NULL;
- MBErrorCode result = mDensePageGroup.get_data(entity, &adj_vec);
- if(result != MB_SUCCESS || adj_vec == NULL) {
- adjacent_entities = NULL;
+ MBAdjacencyVector const* vec_ptr = 0;
+ MBErrorCode result = get_adjacency_ptr( entity, vec_ptr );
+ if (MB_SUCCESS != result || !vec_ptr) {
+ adjacent_entities = 0;
num_entities = 0;
+ return result;
}
- else {
- adjacent_entities = &(*adj_vec)[0];
- num_entities = adj_vec->size();
- }
+
+ num_entities = vec_ptr->size();
+ adjacent_entities = &((*vec_ptr)[0]);
return MB_SUCCESS;
}
MBErrorCode AEntityFactory::get_adjacencies(MBEntityHandle entity,
std::vector<MBEntityHandle>& adjacent_entities) const
{
- MBAdjacencyVector *adj_vec = NULL;
- MBErrorCode result = mDensePageGroup.get_data(entity, &adj_vec);
- if(result != MB_SUCCESS || adj_vec == NULL)
+ MBAdjacencyVector const* vec_ptr = 0;
+ MBErrorCode result = get_adjacency_ptr( entity, vec_ptr );
+ if (MB_SUCCESS != result || !vec_ptr) {
+ adjacent_entities.clear();
return result;
-
- adjacent_entities.resize(adj_vec->size());
- std::copy(adj_vec->begin(), adj_vec->end(), adjacent_entities.begin());
+ }
+
+ adjacent_entities = *vec_ptr;
return MB_SUCCESS;
-
}
+MBErrorCode AEntityFactory::get_adjacencies( MBEntityHandle entity,
+ std::vector<MBEntityHandle>*& adj_vec,
+ bool create )
+{
+ MBErrorCode result = get_adjacency_ptr( entity, adj_vec );
+ if (MB_SUCCESS == result && !adj_vec) {
+ adj_vec = new MBAdjacencyVector;
+ result = set_adjacency_ptr( entity, adj_vec );
+ if (MB_SUCCESS != result)
+ delete adj_vec;
+ }
+ return result;
+}
+
MBErrorCode AEntityFactory::get_adjacencies(const MBEntityHandle entity,
const unsigned int to_dimension,
bool create_if_missing,
@@ -675,7 +656,7 @@
{
// get the adjacency vector
MBAdjacencyVector *adj_vec = NULL;
- result = mDensePageGroup.get_data(source_entity, &adj_vec);
+ result = get_adjacencies( source_entity, adj_vec );
if(result != MB_SUCCESS || adj_vec == NULL)
return result;
@@ -696,7 +677,7 @@
{
// get the adjacency vector
MBAdjacencyVector *adj_vec = NULL;
- result = mDensePageGroup.get_data(source_entity, &adj_vec);
+ result = get_adjacencies( source_entity, adj_vec );
if(result != MB_SUCCESS || adj_vec == NULL)
return result;
@@ -741,7 +722,7 @@
{
// get the adjacency vector
MBAdjacencyVector *adj_vec = NULL;
- result = mDensePageGroup.get_data(source_entity, &adj_vec);
+ result = get_adjacencies( source_entity, adj_vec );
if(result != MB_SUCCESS || adj_vec == NULL)
return result;
@@ -1035,8 +1016,7 @@
// get the adjacency vector
MBAdjacencyVector *adj_vec = NULL;
- result =
- mDensePageGroup.get_data(source_entity, &adj_vec);
+ result = get_adjacencies( source_entity, adj_vec );
if(result != MB_SUCCESS)
return result;
@@ -1273,25 +1253,76 @@
return MB_SUCCESS;
}
+MBErrorCode AEntityFactory::get_adjacency_ptr( MBEntityHandle entity,
+ std::vector<MBEntityHandle>*& ptr )
+{
+ ptr = 0;
+ EntitySequence* seq;
+ MBErrorCode rval = thisMB->sequence_manager()->find( entity, seq );
+ if (MB_SUCCESS != rval || !seq->data()->get_adjacency_data())
+ return rval;
+
+ ptr = seq->data()->get_adjacency_data()[entity - seq->data()->start_handle()];
+ return MB_SUCCESS;
+}
+
+MBErrorCode AEntityFactory::get_adjacency_ptr( MBEntityHandle entity,
+ const std::vector<MBEntityHandle>*& ptr ) const
+{
+ ptr = 0;
+
+ EntitySequence* seq;
+ MBErrorCode rval = thisMB->sequence_manager()->find( entity, seq );
+ if (MB_SUCCESS != rval || !seq->data()->get_adjacency_data())
+ return rval;
+
+ ptr = seq->data()->get_adjacency_data()[entity - seq->data()->start_handle()];
+ return MB_SUCCESS;
+}
+
+
+MBErrorCode AEntityFactory::set_adjacency_ptr( MBEntityHandle entity,
+ std::vector<MBEntityHandle>* ptr )
+{
+ EntitySequence* seq;
+ MBErrorCode rval = thisMB->sequence_manager()->find( entity, seq );
+ if (MB_SUCCESS != rval)
+ return rval;
+
+ if (!seq->data()->get_adjacency_data() && !seq->data()->allocate_adjacency_data())
+ return MB_MEMORY_ALLOCATION_FAILED;
+
+ seq->data()->get_adjacency_data()[entity - seq->data()->start_handle()] = ptr;
+ return MB_SUCCESS;
+}
+
+
void AEntityFactory::get_memory_use( unsigned long& entity_total,
unsigned long& memory_total )
{
- mDensePageGroup.get_memory_use( memory_total, entity_total );
- entity_total = 0;
+ entity_total = memory_total = 0;
- MBAdjacencyVector *adj_vector;
- for (unsigned i = 0; i < MBMAXTYPE; ++i) {
- MBRange ents;
- mDensePageGroup.get_entities( (MBEntityType)i, ents );
-
- // iterate through each entity
- for(MBRange::iterator i = ents.begin(); i != ents.end(); ++i)
- {
- MBErrorCode result = mDensePageGroup.get_data(*i, &adj_vector);
- if(result == MB_SUCCESS && adj_vector)
- entity_total += sizeof(MBEntityHandle) * adj_vector->capacity()
- + sizeof(MBAdjacencyVector);
+ // iterate through each element type
+ SequenceData* prev_data = 0;
+ for (MBEntityType t = MBVERTEX; t != MBENTITYSET; t++) {
+ TypeSequenceManager::iterator i;
+ TypeSequenceManager& seqman = thisMB->sequence_manager()->entity_map( t );
+ for (i = seqman.begin(); i != seqman.end(); ++i) {
+ if (!(*i)->data()->get_adjacency_data())
+ continue;
+
+ if (prev_data != (*i)->data()) {
+ prev_data = (*i)->data();
+ memory_total += prev_data->size() * sizeof(MBAdjacencyVector);
+ }
+
+ const MBAdjacencyVector* vec;
+ for (MBEntityHandle h = (*i)->start_handle(); h <= (*i)->end_handle(); ++h) {
+ get_adjacency_ptr( h, vec );
+ if (vec)
+ entity_total += vec->capacity() * sizeof(MBEntityHandle) * sizeof(MBAdjacencyVector);
+ }
}
}
@@ -1303,35 +1334,34 @@
unsigned long& min_per_ent,
unsigned long& amortized )
{
- // get subset of entities for which adjacency space is allocated
- MBRange tmp_range, tag_range, ents;
- for (unsigned i = 0; i < MBMAXTYPE; ++i) {
- tmp_range.clear();
- mDensePageGroup.get_entities( (MBEntityType)i, tmp_range );
- tag_range.merge( tmp_range );
- }
+ min_per_ent = amortized = 0;
+ MBRangeSeqIntersectIter iter( thisMB->sequence_manager() );
+ MBErrorCode rval = iter.init( ents_in.begin(), ents_in.end() );
+ if (MB_SUCCESS != rval)
+ return rval;
+
+ while (!iter.is_at_end()) {
+ MBAdjacencyVector** array = iter.get_sequence()->data()->get_adjacency_data();
+ if (!array)
+ continue;
- if (tag_range.empty()) {
- min_per_ent = amortized = 0;
- return MB_SUCCESS;
+ MBEntityID count = iter.get_end_handle() - iter.get_start_handle() + 1;
+ MBEntityID data_occ = thisMB->sequence_manager()
+ ->entity_map( iter.get_sequence()->type() )
+ .get_occupied_size( iter.get_sequence()->data() );
+
+ amortized += sizeof(MBAdjacencyVector*)
+ * iter.get_sequence()->data()->size()
+ * count / data_occ;
+
+ array += iter.get_start_handle() - iter.get_sequence()->data()->start_handle();
+ for (MBEntityID i = 0; i < count; ++i) {
+ if (array[i])
+ min_per_ent += sizeof(MBEntityHandle) * array[i]->capacity() + sizeof(MBAdjacencyVector);
+ }
}
- ents = ents_in.intersect( tag_range );
-
- MBAdjacencyVector *adj_vector;
- unsigned long total, per_ent;
- mDensePageGroup.get_memory_use( total, per_ent );
- amortized = total * ents.size() / tag_range.size();
- min_per_ent = 0;
- for(MBRange::iterator i = ents.begin(); i != ents.end(); ++i)
- {
- MBErrorCode result = mDensePageGroup.get_data(*i, &adj_vector);
- if(result == MB_SUCCESS && adj_vector)
- min_per_ent += sizeof(MBEntityHandle) * adj_vector->capacity()
- + sizeof(MBAdjacencyVector);
- }
-
amortized += min_per_ent;
return MB_SUCCESS;
-}
+}
Modified: MOAB/trunk/AEntityFactory.hpp
===================================================================
--- MOAB/trunk/AEntityFactory.hpp 2007-11-12 20:57:20 UTC (rev 1380)
+++ MOAB/trunk/AEntityFactory.hpp 2007-11-12 21:17:17 UTC (rev 1381)
@@ -21,10 +21,10 @@
#endif
#include "MBForward.hpp"
-#include "DenseTagCollections.hpp"
#include <vector>
typedef std::vector<MBEntityHandle> MBAdjacencyVector;
+class MBCore;
//! class AEntityFactory
class AEntityFactory
@@ -32,7 +32,7 @@
public:
//! require an MBInterface object in order to access tags on that interface
- AEntityFactory(MBInterface *mdb);
+ AEntityFactory(MBCore *mdb);
//! destructor
~AEntityFactory();
@@ -98,6 +98,10 @@
MBErrorCode get_adjacencies(MBEntityHandle entity,
const MBEntityHandle *&adjacent_entities,
int &num_entities) const;
+
+ MBErrorCode get_adjacencies( MBEntityHandle entity,
+ std::vector<MBEntityHandle>*& adj_vec_ptr_out,
+ bool create_if_missing = false );
//! returns the entities in sorted order
MBErrorCode get_adjacencies(MBEntityHandle entity,
@@ -142,15 +146,17 @@
private:
+ MBErrorCode get_adjacency_ptr( MBEntityHandle, std::vector<MBEntityHandle>*& );
+ MBErrorCode get_adjacency_ptr( MBEntityHandle, const std::vector<MBEntityHandle>*& ) const;
+ MBErrorCode set_adjacency_ptr( MBEntityHandle, std::vector<MBEntityHandle>* );
+
+
//! private constructor to prevent the construction of a default one
AEntityFactory();
//! interface associated with this tool
- MBInterface *thisMB;
+ MBCore *thisMB;
- //! adjacencies collection
- DensePageGroup mDensePageGroup;
-
//! whether vertex to element adjacencies are begin done
bool mVertElemAdj;
Modified: MOAB/trunk/SequenceData.hpp
===================================================================
--- MOAB/trunk/SequenceData.hpp 2007-11-12 20:57:20 UTC (rev 1380)
+++ MOAB/trunk/SequenceData.hpp 2007-11-12 21:17:17 UTC (rev 1381)
@@ -12,7 +12,7 @@
{
public:
- typedef std::vector<MBEntityHandle> AdjacencyDataType;
+ typedef std::vector<MBEntityHandle>* AdjacencyDataType;
inline SequenceData( int num_sequence_arrays,
MBEntityHandle start,
Modified: MOAB/trunk/SequenceManager.hpp
===================================================================
--- MOAB/trunk/SequenceManager.hpp 2007-11-12 20:57:20 UTC (rev 1380)
+++ MOAB/trunk/SequenceManager.hpp 2007-11-12 21:17:17 UTC (rev 1381)
@@ -90,8 +90,9 @@
EntitySequence*& sequence_out );
+ TypeSequenceManager& entity_map( MBEntityType type )
+ { return typeData[type]; }
-
const TypeSequenceManager& entity_map( MBEntityType type ) const
{ return typeData[type]; }
Modified: MOAB/trunk/TypeSequenceManager.cpp
===================================================================
--- MOAB/trunk/TypeSequenceManager.cpp 2007-11-12 20:57:20 UTC (rev 1380)
+++ MOAB/trunk/TypeSequenceManager.cpp 2007-11-12 21:17:17 UTC (rev 1381)
@@ -828,6 +828,14 @@
}
}
+MBEntityID TypeSequenceManager::get_occupied_size( const SequenceData* data ) const
+{
+ MBEntityID result = 0;
+ for (const_iterator i = data->seqManData.firstSequence; i != end() && (*i)->data() == data; ++i)
+ result += (*i)->size();
+ return result;
+}
+
#ifndef NDEBUG
bool TypeSequenceManager::check_valid_data( const EntitySequence* seq ) const
{
Modified: MOAB/trunk/TypeSequenceManager.hpp
===================================================================
--- MOAB/trunk/TypeSequenceManager.hpp 2007-11-12 20:57:20 UTC (rev 1380)
+++ MOAB/trunk/TypeSequenceManager.hpp 2007-11-12 21:17:17 UTC (rev 1381)
@@ -317,6 +317,13 @@
unsigned long get_sequence_count() const
{ return sequenceSet.size(); }
+
+ /**\brief Get used size of SequenceData
+ *
+ * Get the sum of the size of all EntitySequences referencing
+ * a SequenceData. Used for memory use calculations.
+ */
+ MBEntityID get_occupied_size( const SequenceData* ) const;
};
inline EntitySequence* TypeSequenceManager::find( MBEntityHandle h ) const
More information about the moab-dev
mailing list