Commit 92987ad4 authored by Kirill Terekhov's avatar Kirill Terekhov
Browse files

Enable redistribute with references (working)

parent c1df4764
......@@ -491,7 +491,7 @@ namespace INMOST
// if( it->getNodes().size() != 2 ) {REPORT_STR("edge " << it->LocalID() << " has " << it->getNodes().size() << " nodes ");}
//EXIT_BLOCK();
m->CheckSetLinks(__FILE__,__LINE__);
/*
ENTER_BLOCK();
m->ResolveSets();
......@@ -843,18 +843,20 @@ namespace INMOST
//10.jump to later schedule, and go to 7.
schedule_counter--;
}
m->CheckSetLinks(__FILE__,__LINE__);
//free created tag
m->DeleteTag(indicator,FACE|EDGE);
m->CheckSetLinks(__FILE__,__LINE__);
//11. Restore parallel connectivity, global ids
m->ResolveModification();
//m->SynchronizeMarker(m->NewMarker(),CELL|FACE|EDGE|NODE,SYNC_BIT_OR);
//ExchangeGhost(3,NODE); // Construct Ghost cells in 2 layers connected via nodes
//12. Let the user update their data
//todo: call back function for New() cells
//todo: call back function for New( cells
if( model ) model->Adaptation(*m);
m->CheckSetLinks(__FILE__,__LINE__);
//13. Delete old elements of the mesh
m->ApplyModification();
......
......@@ -44,7 +44,7 @@
// in Mesh::Init function change two variables:
// check_shared_mrk - check shared markers.
// check_private_mrk - check private markers.
#define CHECKS_MARKERS
//#define CHECKS_MARKERS
// use additional sets to store elements for parallel
// exchanges, otherwise it will recompute those elements
......
......@@ -1335,14 +1335,14 @@ namespace INMOST
void AllocatePrivateMarkers();
void DeallocatePrivateMarkers();
__INLINE static sparse_rec mkrec (const Tag & t) {sparse_rec ret; ret.tag = t.mem; ret.rec = NULL; return ret;}
__INLINE sparse_type const & MGetSparseLink (integer etypenum, integer ID) const {return GetSparseData(etypenum,links[etypenum][ID]);}
__INLINE sparse_type & MGetSparseLink (integer etypenum, integer ID) {return GetSparseData(etypenum,links[etypenum][ID]);}
__INLINE sparse_type const & MGetSparseLink (integer etypenum, integer ID) const {assert(links[etypenum][ID] != -1); return GetSparseData(etypenum,links[etypenum][ID]);}
__INLINE sparse_type & MGetSparseLink (integer etypenum, integer ID) {assert(links[etypenum][ID] != -1); return GetSparseData(etypenum,links[etypenum][ID]);}
__INLINE sparse_type const & MGetSparseLink (HandleType h) const {return MGetSparseLink(GetHandleElementNum(h),GetHandleID(h));}
__INLINE sparse_type & MGetSparseLink (HandleType h) {return MGetSparseLink(GetHandleElementNum(h),GetHandleID(h));}
__INLINE const void * MGetSparseLink (HandleType h, const Tag & t) const {sparse_type const & s = MGetSparseLink(GetHandleElementNum(h),GetHandleID(h)); for(senum i = 0; i < s.size(); ++i) if( s[i].tag == t.mem ) return s[i].rec; return NULL;}
__INLINE void * & MGetSparseLink (HandleType h, const Tag & t) {sparse_type & s = MGetSparseLink(GetHandleElementNum(h),GetHandleID(h)); for(senum i = 0; i < s.size(); ++i) if( s[i].tag == t.mem ) return s[i].rec; s.push_back(mkrec(t)); return s.back().rec;}
__INLINE const void * MGetDenseLink (integer n, integer id, const Tag & t) const {return &(GetDenseData(t.GetPositionByDim(n))[links[n][id]]);}
__INLINE void * MGetDenseLink (integer n, integer id, const Tag & t) {return &(GetDenseData(t.GetPositionByDim(n))[links[n][id]]);}
__INLINE const void * MGetDenseLink (integer n, integer ID, const Tag & t) const {assert(links[n][ID] != -1); return &(GetDenseData(t.GetPositionByDim(n))[links[n][ID]]);}
__INLINE void * MGetDenseLink (integer n, integer ID, const Tag & t) {assert(links[n][ID] != -1); return &(GetDenseData(t.GetPositionByDim(n))[links[n][ID]]);}
__INLINE const void * MGetDenseLink (HandleType h, const Tag & t) const {return MGetDenseLink(GetHandleElementNum(h),GetHandleID(h),t);}
__INLINE void * MGetDenseLink (HandleType h, const Tag & t) {return MGetDenseLink(GetHandleElementNum(h),GetHandleID(h),t);}
__INLINE const void * MGetLink (HandleType h, const Tag & t) const {if( !t.isSparseByDim(GetHandleElementNum(h)) ) return MGetDenseLink(h,t); else return MGetSparseLink(h,t);}
......@@ -3241,6 +3241,8 @@ namespace INMOST
void CheckOwners ();
/// Let ghost elements send owner processor to master elements and see if they match
void CheckProcessors ();
/// Checks that there are no invalid links in sets
void CheckSetLinks (std::string file, int line);
//implemented in mesh.cpp
private:
Tag tag_topologyerror;
......
......@@ -1621,7 +1621,7 @@ namespace INMOST
assert(pos.pos < lc.size()); //cannot point over the end
assert(&lc == pos.ptr);
assert(lc[pos.pos] != InvalidHandle()); //cannot point to invalid handles
assert( !m->isMeshModified() || !m->GetMarker(lc[pos.pos],m->HideMarker())); //cannot point to hidden markers
//assert( !m->isMeshModified() || !m->GetMarker(lc[pos.pos],m->HideMarker())); //cannot point to hidden markers
lc[pos.pos] = InvalidHandle();
hc.push_back(pos.pos);
return ++pos;
......
......@@ -1816,6 +1816,7 @@ namespace INMOST
#pragma omp critical (links_interraction)
#endif
{
assert(!isMeshModified());
integer ADDR = links[etypenum][ID];
links[etypenum][ID] = -1;
back_links[etypenum][ADDR] = -1;
......
......@@ -2067,6 +2067,30 @@ namespace INMOST
hide_element = temp_hide_element;
//it->Subtract(erase); //old approach
}
#if defined(USE_PARALLEL_STORAGE)
for(parallel_storage::iterator it = shared_elements.begin(); it != shared_elements.end(); it++)
for(int i = 0; i < 5; i++)
{
unsigned k = 0, l;
for(l = 0; l < it->second[i].size(); ++l)
{
if( !GetMarker(it->second[i][l],hide_element) )
it->second[i][k++] = it->second[i][l];
}
it->second[i].resize(k);
}
for(parallel_storage::iterator it = ghost_elements.begin(); it != ghost_elements.end(); it++)
for(int i = 0; i < 5; i++)
{
unsigned k = 0, l;
for(l = 0; l < it->second[i].size(); ++l)
{
if( !GetMarker(it->second[i][l],hide_element) )
it->second[i][k++] = it->second[i][l];
}
it->second[i].resize(k);
}
#endif
//Destroy(erase);//old approach
EXIT_FUNC();
}
......@@ -2088,8 +2112,11 @@ namespace INMOST
}
std::cout << GetProcessorRank() << " before resolve shared new " << n << " hidden " << h << " both " << hn << std::endl;
*/
CheckSetLinks(__FILE__,__LINE__);
ResolveSets();
CheckSetLinks(__FILE__,__LINE__);
ResolveShared(true);
CheckSetLinks(__FILE__,__LINE__);
//ReportParallelStorage();
//CheckCentroids(__FILE__,__LINE__);
/*
......@@ -2134,6 +2161,7 @@ namespace INMOST
//ApplyModification();
//temp_hide_element = hide_element;
//hide_element = 0;
/*
for(ElementType etype = FACE; etype >= NODE; etype = PrevElementType(etype))
{
for(integer it = 0; it < LastLocalID(etype); ++it) if( isValidElement(etype,it) )
......@@ -2144,16 +2172,20 @@ namespace INMOST
SetMarker(ComposeHandle(etype,it),hide_element);
}
}
*/
MarkerType nm = new_element;
new_element = 0;
for(ElementType etype = ESET; etype >= NODE; etype = PrevElementType(etype))
{
for(integer it = 0; it < LastLocalID(etype); ++it) if( isValidElement(etype,it) )
{
HandleType h = ComposeHandle(etype,it);
RemMarker(h,new_element);
RemMarker(h,nm);
if( GetMarker(h,hide_element) )
Destroy(h);
}
}
new_element = nm;
/*
for(ElementType etype = FACE; etype >= NODE; etype = PrevElementType(etype))
{
......
......@@ -5912,6 +5912,7 @@ namespace INMOST
{
Tag tag_new_owner = GetTag("TEMPORARY_NEW_OWNER");
Tag tag_new_processors = GetTag("TEMPORARY_NEW_PROCESSORS");
/*
for(iteratorTag t = BeginTag(); t != EndTag(); t++)
{
if( t->GetTagName().substr(0,9) == "PROTECTED" ) continue;
......@@ -5940,11 +5941,24 @@ namespace INMOST
}
}
}
*/
CheckSetLinks(__FILE__,__LINE__);
ENTER_BLOCK();
REPORT_STR("Second round for elements migration");
REPORT_STR("Computing new values");
for(iteratorSet it = BeginSet(); it != EndSet(); ++it)
{
ElementSet::iterator jt = it->Begin();
while(jt != it->End())
{
Storage::integer_array procs = jt->IntegerArrayDV(tag_new_processors);
if( !std::binary_search(procs.begin(),procs.end(),mpirank) )
jt = it->Erase(jt);
else jt++;
}
}
for(ElementType etype = NODE; etype <= ESET; etype = NextElementType(etype)) if( tag_new_owner.isDefined(etype) && tag_new_processors.isDefined(etype) )
for(iteratorElement it = BeginElement(etype); it != EndElement(); it++)
......@@ -5967,6 +5981,7 @@ namespace INMOST
Delete(*it);
}
EXIT_BLOCK();
CheckSetLinks(__FILE__,__LINE__);
}
CheckProcsSorted(__FILE__,__LINE__);
......@@ -6120,6 +6135,33 @@ namespace INMOST
#endif //NDEBUG
}
void Mesh::CheckSetLinks(std::string file, int line)
{
ENTER_FUNC();
#if !defined(NDEBUG)
int err = 0;
for(iteratorSet it = BeginSet(); it != EndSet(); ++it)
{
const Element::adj_type & lc = LowConn(*it);
for(Element::adj_type::const_iterator jt = lc.begin(); jt != lc.end(); ++jt)
if( *jt != InvalidHandle() && !isValidElement(*jt) )
{
std::cout << "set " << it->GetName() << " has bad link to " << ElementTypeName(GetHandleElementType(*jt)) << ":" << GetHandleID(*jt) << std::endl;
REPORT_STR("set " << it->GetName() << " has bad link to " << ElementTypeName(GetHandleElementType(*jt)) << ":" << GetHandleID(*jt));
err++;
}
}
err = Integrate(err);
if( err )
{
std::cout << file << ":" <<line << " " << err << " invalid links in sets" << std::endl;
REPORT_STR(file << ":" <<line << " " << err << " invalid links in sets");
exit(-1);
}
#endif //NDEBUG
EXIT_FUNC();
}
void Mesh::CheckCentroids(std::string file, int line)
{
#if !defined(NDEBUG)
......@@ -6389,6 +6431,7 @@ namespace INMOST
Tag layers_marker = CreateTag("TEMPORARY_LAYERS_MARKER",DATA_INTEGER,CELL,CELL);
Integer(GetHandle(),tag_layers) = layers;
Integer(GetHandle(),tag_bridge) = bridge;
CheckSetLinks(__FILE__,__LINE__);
//Storage::integer_array procs = IntegerArrayDV(GetHandle(),tag_processors);
proc_elements old_layers;
proc_elements current_layers;
......@@ -6433,6 +6476,7 @@ namespace INMOST
}
for(Storage::integer k = layers-1; k >= 0; k--)
{
CheckSetLinks(__FILE__,__LINE__);
ExchangeMarked();
old_layers.swap(current_layers);
current_layers.clear();
......@@ -6484,6 +6528,7 @@ namespace INMOST
}
if( delete_ghost )
{
CheckSetLinks(__FILE__,__LINE__);
time = Timer();
ReduceData(layers_marker,CELL,0,UnpackLayersMarker);
ExchangeData(layers_marker,CELL,0);
......@@ -6517,6 +6562,7 @@ namespace INMOST
REPORT_STR("Select ghost elements to remove");
REPORT_VAL("time",time);
RemoveGhostElements(del_ghost);
CheckSetLinks(__FILE__,__LINE__);
//Save("after_delete_ghost.pvtk");
//exit(-1);
}
......
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