put sanity check of thread groups in a shared method

avoids some code duplication
This commit is contained in:
Arne Morten Kvarving 2016-12-15 11:18:42 +01:00
parent 383390ebba
commit 78b6096f88
4 changed files with 37 additions and 26 deletions

View File

@ -2626,7 +2626,6 @@ void ASMs2D::generateThreadGroups (size_t strip1, size_t strip2,
for (size_t i = 0; i < threadGroups.size(); i++)
{
std::vector< std::set<int> > nodes(threadGroups[i].size());
std::set<int>::const_iterator nit;
std::cout <<"\n Thread group "<< i+1;
for (size_t j = 0; j < threadGroups[i].size(); j++)
@ -2645,19 +2644,9 @@ void ASMs2D::generateThreadGroups (size_t strip1, size_t strip2,
}
if (nzeroar > 0)
std::cout <<" ("<< threadGroups[i][j].size() - nzeroar <<" real)";
#if SP_DEBUG > 1
nit = nodes[j].begin();
std::cout <<"\n\t nodes: "<< *(nit++);
for (k = 1; nit != nodes[j].end(); ++nit, k++)
std::cout << (k%10 > 0 ? " " : "\n\t ") << *nit;
#endif
// Verify that the nodes on this thread are not present on the others
for (k = 0; k < j; k++)
for (nit = nodes[j].begin(); nit != nodes[j].end(); ++nit)
if ((this->getLMType(*nit+1) != 'G' || !ignoreGlobalLM) &&
nodes[k].find(*nit) != nodes[k].end())
std::cout <<"\n ** Warning: Node "<< *nit <<" is present on both"
<<" thread "<< k+1 <<" and thread "<< j+1;
this->checkThreadGroups(nodes, j, ignoreGlobalLM);
}
}
std::cout << std::endl;

View File

@ -3014,7 +3014,6 @@ void ASMs3D::generateThreadGroups (size_t strip1, size_t strip2, size_t strip3,
for (size_t i = 0; i < threadGroupsVol.size(); i++)
{
std::vector< std::set<int> > nodes(threadGroupsVol[i].size());
std::set<int>::const_iterator nit;
std::cout <<"\n Thread group "<< i+1;
for (size_t j = 0; j < threadGroupsVol[i].size(); j++)
@ -3033,19 +3032,9 @@ void ASMs3D::generateThreadGroups (size_t strip1, size_t strip2, size_t strip3,
}
if (nzerovol)
std::cout <<" ("<< threadGroupsVol[i][j].size() - nzerovol <<" real)";
#if SP_DEBUG > 1
nit = nodes[j].begin();
std::cout <<"\n\t nodes: "<< *(nit++);
for (k = 1; nit != nodes[j].end(); ++nit, k++)
std::cout << (k%10 > 0 ? " " : "\n\t ") << *nit;
#endif
// Verify that the nodes on this thread are not present on the others
for (k = 0; k < j; k++)
for (nit = nodes[j].begin(); nit != nodes[j].end(); ++nit)
if ((this->getLMType(*nit+1) != 'G' || !ignoreGlobalLM) &&
nodes[k].find(*nit) != nodes[k].end())
std::cout <<"\n ** Warning: Node "<< *nit <<" is present on both"
<<" thread "<< k+1 <<" and thread "<< j+1;
this->checkThreadGroups(nodes, j, ignoreGlobalLM);
}
}
std::cout << std::endl;

View File

@ -84,3 +84,27 @@ bool ASMstruct::addXNodes (unsigned short int dim, size_t nXn, IntVec& nodes)
return true;
}
bool ASMstruct::checkThreadGroups (const std::vector<std::set<int>>& nodes,
int group, bool ignoreGlobalLM)
{
#if SP_DEBUG > 1
auto nit = nodes[group].begin();
std::cout <<"\n\t nodes: "<< *(nit++);
for (int k = 1; nit != nodes[group].end(); ++nit, k++)
std::cout << (k%10 > 0 ? " " : "\n\t ") << *nit;
#endif
bool ok = true;
for (int k = 0; k < group; k++)
for (const int& node : nodes[group])
if ((this->getLMType(node+1) != 'G' || !ignoreGlobalLM) &&
nodes[k].find(node) != nodes[k].end()) {
std::cout <<"\n ** Warning: Node "<< node <<" is present on both"
<<" thread "<< k+1 <<" and thread "<< group+1;
ok = false;
}
return ok;
}

View File

@ -76,6 +76,15 @@ protected:
//! of the dimension-specific sub-classes.
bool addXNodes(unsigned short int dim, size_t nXn, IntVec& nodes);
//! \brief Perform a sanity check on the thread groups.
//! \param[in] nodes The nodes to santiy check
//! \param[in] group The group to check for
//! \param[in] ignoreGlobalLM If \e true, ignore global lagrange multipliers
//! \return If \e true groups pass checks.
//! \details This checks that no nodes exist on several threads
bool checkThreadGroups(const std::vector<std::set<int>>& nodes,
int group, bool ignoreGlobalLM);
protected:
Go::GeomObject* geo; //!< Pointer to the actual spline geometry object