Skip to content

Commit b656e6c

Browse files
committed
Added option to run FESolidDomain::ForEachSolidElement in parallel.
1 parent 3697c99 commit b656e6c

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

FECore/FESolidDomain.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,19 @@ int FESolidDomain::Elements() const { return (int)m_Elem.size(); }
8484

8585
//-----------------------------------------------------------------------------
8686
//! loop over elements
87-
void FESolidDomain::ForEachSolidElement(std::function<void(FESolidElement& el)> f)
87+
void FESolidDomain::ForEachSolidElement(std::function<void(FESolidElement& el)> f, bool runInParallel)
8888
{
8989
int NE = Elements();
90-
for (int i = 0; i < NE; ++i) f(m_Elem[i]);
90+
if (runInParallel)
91+
{
92+
#pragma omp parallel for
93+
for (int i = 0; i < NE; ++i)
94+
f(m_Elem[i]);
95+
}
96+
else
97+
{
98+
for (int i = 0; i < NE; ++i) f(m_Elem[i]);
99+
}
91100
}
92101

93102
//-----------------------------------------------------------------------------
@@ -141,7 +150,7 @@ bool FESolidDomain::Init()
141150
// material point coordinates
142151
mp.m_r0 = el.Evaluate(r0, n);
143152
}
144-
});
153+
}, false);
145154
}
146155
catch (NegativeJacobian e)
147156
{

FECore/FESolidDomain.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ class FECORE_API FESolidDomain : public FEDomain
263263

264264
public:
265265
//! loop over elements
266-
void ForEachSolidElement(std::function<void(FESolidElement& el)> f);
266+
void ForEachSolidElement(std::function<void(FESolidElement& el)> f, bool runInParallel = true);
267267

268268
//! return the degrees of freedom of an element for this domain
269269
virtual int GetElementDofs(FESolidElement& el);

0 commit comments

Comments
 (0)