Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added: callback for changing number of threads #734

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ASM/ASMbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ class ASMbase
//! \brief Generate element-groups for multi-threading based on a partition.
virtual void generateThreadGroupsFromElms(const IntVec&) {}

//! \brief Hook for changing number of threads.
virtual void changeNumThreads() {}

// Methods for integration of finite element quantities.
// These are the main computational methods of the ASM class hierarchy.
Expand Down
7 changes: 7 additions & 0 deletions src/ASM/ASMs2D.C
Original file line number Diff line number Diff line change
Expand Up @@ -3098,6 +3098,13 @@ void ASMs2D::generateThreadGroups (size_t strip1, size_t strip2,
}


void ASMs2D::changeNumThreads ()
{
for (std::unique_ptr<BasisFunctionCache>& c : myCache)
c->resizeThreadBuffers();
}


bool ASMs2D::getNoStructElms (int& n1, int& n2, int& n3) const
{
n1 = surf->numCoefs_u() - surf->order_u() + 1;
Expand Down
3 changes: 3 additions & 0 deletions src/ASM/ASMs2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,9 @@ class ASMs2D : public ASMstruct, public ASM2D
virtual void generateThreadGroups(const Integrand& integrand, bool silence,
bool ignoreGlobalLM);

//! \brief Hook for changing number of threads.
virtual void changeNumThreads();

//! \brief Generates element groups for multi-threading of interior integrals.
//! \param[in] strip1 Strip width in first direction
//! \param[in] strip2 Strip width in second direction
Expand Down
7 changes: 7 additions & 0 deletions src/ASM/ASMs3D.C
Original file line number Diff line number Diff line change
Expand Up @@ -3531,6 +3531,13 @@ void ASMs3D::generateThreadGroups (size_t strip1, size_t strip2, size_t strip3,
}


void ASMs3D::changeNumThreads ()
{
for (std::unique_ptr<BasisFunctionCache>& c : myCache)
c->resizeThreadBuffers();
}


void ASMs3D::generateThreadGroups (char lIndex, bool silence, bool)
{
std::map<char,ThreadGroups>::iterator tit = threadGroupsFace.find(lIndex);
Expand Down
3 changes: 3 additions & 0 deletions src/ASM/ASMs3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,9 @@ class ASMs3D : public ASMstruct, public ASM3D
void generateThreadGroups(size_t strip1, size_t strip2, size_t strip3,
bool silence, bool ignoreGlobalLM);

//! \brief Hook for changing number of threads.
virtual void changeNumThreads();

//! \brief Returns 0-based index of first node on integration basis.
virtual int getFirstItgElmNode() const { return 0; }
//! \brief Returns 0-based index of last node on integration basis.
Expand Down
26 changes: 18 additions & 8 deletions src/ASM/BasisFunctionCache.C
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,10 @@ bool BasisFunctionCache<Dim>::init (int nd)
return false;

if (ASM::cachePolicy == ASM::NO_CACHE) {
#ifdef USE_OPENMP
size_t size = omp_get_max_threads();
#else
size_t size = 1;
#endif
values.resize(size);
if (this->hasReduced())
valuesRed.resize(size);
this->resizeThreadBuffers();
return true;
}

values.resize(nTotal);
if (this->hasReduced())
valuesRed.resize(nTotalRed);
Expand Down Expand Up @@ -135,5 +129,21 @@ BasisFunctionCache<Dim>::gpIndex (size_t gp, bool reduced) const
}


template<size_t Dim>
void BasisFunctionCache<Dim>::resizeThreadBuffers ()
{
if (ASM::cachePolicy == ASM::NO_CACHE) {
#ifdef USE_OPENMP
size_t size = omp_get_max_threads();
#else
size_t size = 1;
#endif
values.resize(size);
if (this->hasReduced())
valuesRed.resize(size);
}
}


template class BasisFunctionCache<2>;
template class BasisFunctionCache<3>;
3 changes: 3 additions & 0 deletions src/ASM/BasisFunctionCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ template<size_t Dim> class BasisFunctionCache

int basis = 1; //!< Basis to use

//! \brief Called if application changes number of threads.
void resizeThreadBuffers();

protected:
//! \brief Template struct holding information about a quadrature.
struct Quadrature {
Expand Down
7 changes: 7 additions & 0 deletions src/ASM/LR/ASMu2D.C
Original file line number Diff line number Diff line change
Expand Up @@ -2643,6 +2643,13 @@ void ASMu2D::generateThreadGroups (const Integrand& integrand, bool silence,
}


void ASMu2D::changeNumThreads ()
{
for (std::unique_ptr<BasisFunctionCache>& c : myCache)
c->resizeThreadBuffers();
}


void ASMu2D::remapErrors (RealArray& errors,
const RealArray& origErr, bool elemErrors) const
{
Expand Down
3 changes: 3 additions & 0 deletions src/ASM/LR/ASMu2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,9 @@ class ASMu2D : public ASMLRSpline, public ASM2D
//! \brief Generate element groups from a partition.
virtual void generateThreadGroupsFromElms(const std::vector<int>& elms);

//! \brief Hook for changing number of threads.
virtual void changeNumThreads();

//! \brief Remap element wise errors to basis functions.
//! \param errors The remapped errors
//! \param[in] origErr The element wise errors on the geometry mesh
Expand Down
7 changes: 7 additions & 0 deletions src/ASM/LR/ASMu3D.C
Original file line number Diff line number Diff line change
Expand Up @@ -1916,6 +1916,13 @@ void ASMu3D::generateThreadGroups (const Integrand& integrand, bool silence,
}


void ASMu3D::changeNumThreads ()
{
for (std::unique_ptr<BasisFunctionCache>& c : myCache)
c->resizeThreadBuffers();
}


bool ASMu3D::updateDirichlet (const std::map<int,RealFunc*>& func,
const std::map<int,VecFunc*>& vfunc, double time,
const std::map<int,int>* g2l)
Expand Down
3 changes: 3 additions & 0 deletions src/ASM/LR/ASMu3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,9 @@ class ASMu3D : public ASMLRSpline, public ASM3D
//! \brief Generate element groups from a partition.
virtual void generateThreadGroupsFromElms(const std::vector<int>& elms);

//! \brief Hook for changing number of threads.
virtual void changeNumThreads();

//! \brief Remap element wise errors to basis functions.
//! \param errors The remapped errors
//! \param[in] origErr The element wise errors on the geometry mesh
Expand Down
8 changes: 8 additions & 0 deletions src/SIM/SIMbase.C
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,14 @@ void SIMbase::generateThreadGroups (const Property& p, bool silence)
}


void SIMbase::changeNumThreads ()
{
for (ASMbase* pch : myModel)
if (!pch->empty())
pch->changeNumThreads();
}


VecFunc* SIMbase::getVecFunc (size_t patch, Property::Type ptype) const
{
for (PropertyVec::const_iterator p = myProps.begin(); p != myProps.end(); ++p)
Expand Down
3 changes: 3 additions & 0 deletions src/SIM/SIMbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,9 @@ class SIMbase : public SIMadmin, public SIMdependency
//! \param[in] silence If \e true, suppress threading group outprint
void generateThreadGroups(const Property& p, bool silence = false);

//! \brief Called if number of threads changes.
void changeNumThreads();

//! \brief Adds a MADOF with an extraordinary number of DOFs on a given basis.
//! \param[in] basis The basis to specify number of DOFs for
//! \param[in] nndof Number of nodal DOFs on the given basis
Expand Down