Commit bd7030d7 authored by Kirill Terekhov's avatar Kirill Terekhov

Fixes in memory management for data with derivatives

parent b033a1cb
...@@ -334,7 +334,7 @@ namespace INMOST ...@@ -334,7 +334,7 @@ namespace INMOST
{ {
new_tag = Tag(m,name,dtype,size); new_tag = Tag(m,name,dtype,size);
#if defined(USE_OMP) #if defined(USE_OMP)
#pragma omp critical #pragma omp critical (change_tags)
#endif #endif
{ {
tags.push_back(new_tag); tags.push_back(new_tag);
...@@ -356,7 +356,7 @@ namespace INMOST ...@@ -356,7 +356,7 @@ namespace INMOST
{ {
INMOST_DATA_ENUM_TYPE new_pos = ENUMUNDEF; INMOST_DATA_ENUM_TYPE new_pos = ENUMUNDEF;
#if defined(USE_OMP) #if defined(USE_OMP)
#pragma omp critical #pragma omp critical (change_data)
#endif #endif
{ {
new_pos = static_cast<INMOST_DATA_ENUM_TYPE>(dense_data.size()); new_pos = static_cast<INMOST_DATA_ENUM_TYPE>(dense_data.size());
...@@ -384,7 +384,7 @@ namespace INMOST ...@@ -384,7 +384,7 @@ namespace INMOST
if( new_size < 1024 && j != ElementNum(MESH) ) new_size = 1024; if( new_size < 1024 && j != ElementNum(MESH) ) new_size = 1024;
if( new_size != 1 && j == ElementNum(MESH) ) new_size = 1; if( new_size != 1 && j == ElementNum(MESH) ) new_size = 1;
#if defined(USE_OMP) #if defined(USE_OMP)
#pragma omp critical #pragma omp critical (change_data)
#endif #endif
{ {
sparse_data[j].resize(new_size); sparse_data[j].resize(new_size);
...@@ -424,9 +424,9 @@ namespace INMOST ...@@ -424,9 +424,9 @@ namespace INMOST
if( !tag.isSparse(mask) ) if( !tag.isSparse(mask) )
{ {
//this was already done in Mesh::DeleteTag() //this was already done in Mesh::DeleteTag()
//ReallocateData(tag,ElementNum(mask),0); //this should clean up the structures ReallocateData(tag,ElementNum(mask),0); //this should clean up the structures
dense_data[tpos].clear(); //here all data should be deleted dense_data[tpos].clear(); //here all data should be deleted
empty_dense_data.push_back(tpos); empty_dense_data.push_back(tpos);
} }
#if !defined(LAZY_SPARSE_ALLOCATION) #if !defined(LAZY_SPARSE_ALLOCATION)
else was_sparse[ElementNum(mask)] = true; else was_sparse[ElementNum(mask)] = true;
...@@ -447,14 +447,17 @@ namespace INMOST ...@@ -447,14 +447,17 @@ namespace INMOST
} }
for(int j = 0; j < 6; j++) for(int j = 0; j < 6; j++)
if( was_sparse[j] && !have_sparse[j] ) if( was_sparse[j] && !have_sparse[j] )
sparse_data[j].clear(); {
//ReallocateData(tag,j,0); //this should clean up the structures
sparse_data[j].clear();
}
#endif #endif
for(tag_array_type::size_type i = 0; i < tags.size(); i++) for(tag_array_type::size_type i = 0; i < tags.size(); i++)
{ {
if( tags[i] == tag ) if( tags[i] == tag )
{ {
tags.erase(tags.begin()+i); tags.erase(tags.begin()+i);
flag = true; flag = true;
break; break;
} }
} }
...@@ -519,6 +522,7 @@ namespace INMOST ...@@ -519,6 +522,7 @@ namespace INMOST
void TagManager::ReallocateData(const Tag & t, INMOST_DATA_INTEGER_TYPE etypenum, INMOST_DATA_ENUM_TYPE new_size) void TagManager::ReallocateData(const Tag & t, INMOST_DATA_INTEGER_TYPE etypenum, INMOST_DATA_ENUM_TYPE new_size)
{ {
//std::cout << "reallocate for " << t.GetTagName() << " type " << DataTypeName(t.GetDataType()) << " element type " << ElementTypeName(ElementTypeFromDim(etypenum)) << " size " << new_size << std::endl;
INMOST_DATA_ENUM_TYPE data_pos = t.GetPositionByDim(etypenum); INMOST_DATA_ENUM_TYPE data_pos = t.GetPositionByDim(etypenum);
INMOST_DATA_ENUM_TYPE data_size = t.GetSize(); INMOST_DATA_ENUM_TYPE data_size = t.GetSize();
TagManager::dense_sub_type & arr = GetDenseData(data_pos); TagManager::dense_sub_type & arr = GetDenseData(data_pos);
...@@ -554,7 +558,7 @@ namespace INMOST ...@@ -554,7 +558,7 @@ namespace INMOST
} }
#endif #endif
#if defined(USE_OMP) #if defined(USE_OMP)
#pragma omp critical #pragma omp critical (change_data)
#endif #endif
{ {
arr.resize(new_size); arr.resize(new_size);
......
...@@ -58,7 +58,7 @@ namespace INMOST ...@@ -58,7 +58,7 @@ namespace INMOST
out << INMOST::INMOSTFile; out << INMOST::INMOSTFile;
out << INMOST::MeshHeader; out << INMOST::MeshHeader;
//ReorderEmpty(NODE | EDGE | FACE | CELL | ESET); ReorderEmpty(NODE | EDGE | FACE | CELL | ESET);
uconv.write_iByteOrder(out); uconv.write_iByteOrder(out);
uconv.write_iByteSize(out); uconv.write_iByteSize(out);
......
...@@ -166,7 +166,7 @@ namespace INMOST ...@@ -166,7 +166,7 @@ namespace INMOST
tag_setname = CreateTag("PROTECTED_SET_NAME",DATA_BULK,ESET,NONE); tag_setname = CreateTag("PROTECTED_SET_NAME",DATA_BULK,ESET,NONE);
tag_setcomparator = CreateTag("PROTECTED_SET_COMPARATOR",DATA_BULK,ESET,NONE,1); tag_setcomparator = CreateTag("PROTECTED_SET_COMPARATOR",DATA_BULK,ESET,NONE,1);
AllocatePrivateMarkers(); AllocatePrivateMarkers();
for(ElementType etype = NODE; etype <= MESH; etype = etype << 1) for(ElementType etype = NODE; etype <= MESH; etype = NextElementType(etype))
ReallocateData(ElementNum(etype),GetArrayCapacity(ElementNum(etype))); ReallocateData(ElementNum(etype),GetArrayCapacity(ElementNum(etype)));
epsilon = 1.0e-8; epsilon = 1.0e-8;
m_state = Mesh::Serial; m_state = Mesh::Serial;
...@@ -392,7 +392,7 @@ namespace INMOST ...@@ -392,7 +392,7 @@ namespace INMOST
tag_geom_type = CreateTag("PROTECTED_GEOM_TYPE",DATA_BULK,CELL|FACE|EDGE|NODE,NONE,1); tag_geom_type = CreateTag("PROTECTED_GEOM_TYPE",DATA_BULK,CELL|FACE|EDGE|NODE,NONE,1);
tag_setname = CreateTag("PROTECTED_SET_NAME",DATA_BULK,ESET,NONE); tag_setname = CreateTag("PROTECTED_SET_NAME",DATA_BULK,ESET,NONE);
tag_setcomparator = CreateTag("PROTECTED_SET_COMPARATOR",DATA_BULK,ESET,NONE,1); tag_setcomparator = CreateTag("PROTECTED_SET_COMPARATOR",DATA_BULK,ESET,NONE,1);
AllocatePrivateMarkers(); AllocatePrivateMarkers();
//copy supplimentary values //copy supplimentary values
m_state = other.m_state; m_state = other.m_state;
checkset = other.checkset; checkset = other.checkset;
...@@ -409,7 +409,7 @@ namespace INMOST ...@@ -409,7 +409,7 @@ namespace INMOST
//this is not needed as it was copied with all the other data //this is not needed as it was copied with all the other data
//recompute global ids //recompute global ids
//AssignGlobalID(other.have_global_id); //AssignGlobalID(other.have_global_id);
allocated_meshes.push_back(this); allocated_meshes.push_back(this);
} }
Mesh & Mesh::operator =(Mesh const & other) Mesh & Mesh::operator =(Mesh const & other)
...@@ -435,6 +435,7 @@ namespace INMOST ...@@ -435,6 +435,7 @@ namespace INMOST
} }
#endif #endif
#endif #endif
//clear all data fields //clear all data fields
for(ElementType etype = NODE; etype <= MESH; etype = NextElementType(etype)) for(ElementType etype = NODE; etype <= MESH; etype = NextElementType(etype))
{ {
...@@ -463,6 +464,7 @@ namespace INMOST ...@@ -463,6 +464,7 @@ namespace INMOST
} }
} }
} }
//clear links //clear links
for(int i = 0; i < 5; i++) for(int i = 0; i < 5; i++)
{ {
...@@ -471,6 +473,7 @@ namespace INMOST ...@@ -471,6 +473,7 @@ namespace INMOST
empty_space[i].clear(); empty_space[i].clear();
} }
DeallocatePrivateMarkers(); DeallocatePrivateMarkers();
//while( !tags.empty() ) DeleteTag(tags.back(),CELL|FACE|EDGE|NODE|ESET|MESH);
//this should copy tags, clear sparse data, set up dense links //this should copy tags, clear sparse data, set up dense links
TagManager::operator =(other); TagManager::operator =(other);
//set up new links //set up new links
...@@ -517,7 +520,7 @@ namespace INMOST ...@@ -517,7 +520,7 @@ namespace INMOST
tag_geom_type = CreateTag("PROTECTED_GEOM_TYPE",DATA_BULK,CELL|FACE|EDGE|NODE,NONE,1); tag_geom_type = CreateTag("PROTECTED_GEOM_TYPE",DATA_BULK,CELL|FACE|EDGE|NODE,NONE,1);
tag_setname = CreateTag("PROTECTED_SET_NAME",DATA_BULK,ESET,NONE); tag_setname = CreateTag("PROTECTED_SET_NAME",DATA_BULK,ESET,NONE);
tag_setcomparator = CreateTag("PROTECTED_SET_COMPARATOR",DATA_BULK,ESET,NONE,1); tag_setcomparator = CreateTag("PROTECTED_SET_COMPARATOR",DATA_BULK,ESET,NONE,1);
AllocatePrivateMarkers(); AllocatePrivateMarkers();
//copy supplimentary values //copy supplimentary values
m_state = other.m_state; m_state = other.m_state;
checkset = other.checkset; checkset = other.checkset;
...@@ -539,6 +542,8 @@ namespace INMOST ...@@ -539,6 +542,8 @@ namespace INMOST
void Mesh::Clear() void Mesh::Clear()
{ {
/*
for(ElementType etype = NODE; etype <= MESH; etype = NextElementType(etype)) for(ElementType etype = NODE; etype <= MESH; etype = NextElementType(etype))
{ {
for(tag_array_type::size_type i = 0; i < tags.size(); ++i) for(tag_array_type::size_type i = 0; i < tags.size(); ++i)
...@@ -566,8 +571,10 @@ namespace INMOST ...@@ -566,8 +571,10 @@ namespace INMOST
} }
} }
} }
*/
DeallocatePrivateMarkers(); DeallocatePrivateMarkers();
memset(remember,0,sizeof(bool)*15); memset(remember,0,sizeof(bool)*15);
while( !tags.empty() ) DeleteTag(tags.back(),CELL|FACE|EDGE|NODE|ESET|MESH);
tags.clear(); tags.clear();
//clear links //clear links
dense_data.clear(); dense_data.clear();
...@@ -590,6 +597,8 @@ namespace INMOST ...@@ -590,6 +597,8 @@ namespace INMOST
Mesh::~Mesh() Mesh::~Mesh()
{ {
//clear all data fields //clear all data fields
//while( !tags.empty() ) DeleteTag(tags.back(),CELL|FACE|EDGE|NODE|ESET|MESH);
/*
for(ElementType etype = NODE; etype <= MESH; etype = NextElementType(etype)) for(ElementType etype = NODE; etype <= MESH; etype = NextElementType(etype))
{ {
for(tag_array_type::size_type i = 0; i < tags.size(); ++i) for(tag_array_type::size_type i = 0; i < tags.size(); ++i)
...@@ -617,7 +626,9 @@ namespace INMOST ...@@ -617,7 +626,9 @@ namespace INMOST
} }
} }
} }
*/
DeallocatePrivateMarkers(); DeallocatePrivateMarkers();
while( !tags.empty() ) DeleteTag(tags.back(),CELL|FACE|EDGE|NODE|ESET|MESH);
//clear links //clear links
for(int i = 0; i < 5; i++) for(int i = 0; i < 5; i++)
{ {
...@@ -674,6 +685,9 @@ namespace INMOST ...@@ -674,6 +685,9 @@ namespace INMOST
} }
Tag Mesh::DeleteTag(Tag tag, ElementType type_mask) Tag Mesh::DeleteTag(Tag tag, ElementType type_mask)
{ {
std::cout << "Delete tag " << tag.GetTagName() << " type " << DataTypeName(tag.GetDataType()) << " on ";
for(ElementType etype = NODE; etype <= MESH; etype = NextElementType(etype)) if( (etype & type_mask) && tag.isDefined(etype) ) std::cout << ElementTypeName(etype) << " ";
std::cout << std::endl;
//deallocate data on elements //deallocate data on elements
for(ElementType etype = NODE; etype <= MESH; etype = NextElementType(etype)) for(ElementType etype = NODE; etype <= MESH; etype = NextElementType(etype))
{ {
...@@ -700,7 +714,7 @@ namespace INMOST ...@@ -700,7 +714,7 @@ namespace INMOST
} }
} }
#if defined(USE_OMP) #if defined(USE_OMP)
#pragma omp critical #pragma omp critical (change_tags)
#endif #endif
{ {
tag = TagManager::DeleteTag(tag,type_mask); tag = TagManager::DeleteTag(tag,type_mask);
...@@ -1862,6 +1876,14 @@ namespace INMOST ...@@ -1862,6 +1876,14 @@ namespace INMOST
TagManager::dense_sub_type & arr = GetDenseData(data_pos); TagManager::dense_sub_type & arr = GetDenseData(data_pos);
INMOST_DATA_ENUM_TYPE record_size = t->GetRecordSize(); INMOST_DATA_ENUM_TYPE record_size = t->GetRecordSize();
memcpy(&arr[new_addr],&arr[old_addr],record_size); memcpy(&arr[new_addr],&arr[old_addr],record_size);
#if defined(USE_AUTODIFF)
if( t->GetDataType() == DATA_VARIABLE )
{
variable * p = static_cast<variable *>(static_cast<void *>(&arr[old_addr]));
for(INMOST_DATA_ENUM_TYPE j = 0; j < t->GetSize(); ++j) p[j] = 0.0;
}
else
#endif
memset(&arr[old_addr],0,record_size); memset(&arr[old_addr],0,record_size);
} }
} }
...@@ -2384,8 +2406,8 @@ namespace INMOST ...@@ -2384,8 +2406,8 @@ namespace INMOST
#if defined(USE_AUTODIFF) #if defined(USE_AUTODIFF)
else if( tag.GetDataType() == DATA_VARIABLE ) //Have to deallocate the structure to remove inheritance else if( tag.GetDataType() == DATA_VARIABLE ) //Have to deallocate the structure to remove inheritance
{ {
for(INMOST_DATA_ENUM_TYPE k = 0; k < tag.GetSize(); ++k) for(INMOST_DATA_ENUM_TYPE k = 0; k < tag.GetSize(); ++k) (static_cast<variable *>(data)[k]) = 0.0;
(static_cast<variable *>(data)[k]).~variable(); //(static_cast<variable *>(data)[k]).~variable();
} }
#endif #endif
//else if( tag.GetDataType() == DATA_REFERENCE ) //else if( tag.GetDataType() == DATA_REFERENCE )
......
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