[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Getfem-commits] (no subject)
From: |
Andriy Andreykiv |
Subject: |
[Getfem-commits] (no subject) |
Date: |
Fri, 21 Dec 2018 12:33:21 -0500 (EST) |
branch: consistent_partitioning_for_open_mp
commit 407e1d8645d230bf7dcb802b5b6f0a5264f85026
Author: Andriy.Andreykiv <address@hidden>
Date: Mon Nov 19 12:03:05 2018 +0100
Macro that encapsulates the parallel Open MP run
---
src/getfem/getfem_omp.h | 12 +++++++++---
src/getfem_models.cc | 30 +++++++-----------------------
src/getfem_omp.cc | 12 +++++++++++-
3 files changed, 27 insertions(+), 27 deletions(-)
diff --git a/src/getfem/getfem_omp.h b/src/getfem/getfem_omp.h
index 3147a5e..d264c7c 100644
--- a/src/getfem/getfem_omp.h
+++ b/src/getfem/getfem_omp.h
@@ -377,15 +377,21 @@ namespace getfem
/**vector of pointers to caught exceptions*/
std::vector<std::exception_ptr> caughtExceptions() const;
void rethrow();
-
+
private:
void captureException();
std::vector<std::exception_ptr> exceptions_;
};
+ void parallel_execution(std::function<void(void)> lambda);
-}
+#ifdef GETFEM_HAVE_OPENMP
+ #define GETFEM_OMP_PARALLEL(body) parallel_execution([&](){body;});
+#else
+ #define GETFEM_OMP_PARALLEL(body) body
+#endif
-#endif //GETFEM_OMP
+}
+#endif //GETFEM_OMP
\ No newline at end of file
diff --git a/src/getfem_models.cc b/src/getfem_models.cc
index 4f55c21..288569e 100644
--- a/src/getfem_models.cc
+++ b/src/getfem_models.cc
@@ -516,22 +516,14 @@ namespace getfem {
{
gmm::clear(rTM);
distro<decltype(rTM)> distro_rTM(rTM);
- gmm::standard_locale locale;
- open_mp_is_running_properly check;
- thread_exception exception;
- #pragma omp parallel default(shared)
- {
- exception.run([&]
- {
+ GETFEM_OMP_PARALLEL(
ga_workspace workspace(*this);
for (const auto &ge : generic_expressions)
workspace.add_expression(ge.expr, ge.mim, ge.region,
- 2, ge.secondary_domain);
+ 2, ge.secondary_domain);
workspace.set_assembled_matrix(distro_rTM);
workspace.assembly(2);
- });
- } //parallel
- exception.rethrow();
+ );
} //distro scope
gmm::add
(gmm::sub_matrix(rTM, vdescr.I, multdescr.I), MM);
@@ -1939,13 +1931,7 @@ namespace getfem {
list_distro<real_veclist> rveclist_sym(brick.rveclist_sym[rhs_ind]);
/*running the assembly in parallel*/
- gmm::standard_locale locale;
- open_mp_is_running_properly check;
- thread_exception exception;
- #pragma omp parallel default(shared)
- {
- exception.run([&]
- {
+ GETFEM_OMP_PARALLEL(
brick.pbr->asm_real_tangent_terms(*this, ib, brick.vlist,
brick.dlist, brick.mims,
rmatlist,
@@ -1953,9 +1939,7 @@ namespace getfem {
rveclist_sym,
brick.region,
version);
- } );
- }
- exception.rethrow();
+ );
}
brick.pbr->real_post_assembly_in_serial(*this, ib, brick.vlist,
brick.dlist, brick.mims,
@@ -3409,7 +3393,7 @@ model_complex_plain_vector &
return md.add_brick(pbr, vl, dl, tl, model::mimlist(1, &mim), region);
}
-
+
size_type add_source_term
(model &md, const mesh_im &mim, const std::string &expr, size_type region,
const std::string &brickname, const std::string &directvarname,
@@ -3426,7 +3410,7 @@ model_complex_plain_vector &
return add_source_term_(md, mim, expr, region, brickname, directvarname,
directdataname, return_if_nonlin,
secondary_domain);
}
-
+
// ----------------------------------------------------------------------
//
// Linear generic assembly brick
diff --git a/src/getfem_omp.cc b/src/getfem_omp.cc
index 3bb9b65..1c0c084 100644
--- a/src/getfem_omp.cc
+++ b/src/getfem_omp.cc
@@ -161,4 +161,14 @@ namespace getfem{
exceptions_[this_thread()] = std::current_exception();
}
-}
+ void parallel_execution(std::function<void(void)> lambda){
+ gmm::standard_locale locale;
+ thread_exception exception;
+ #pragma omp parallel default(shared)
+ {
+ exception.run([&]{lambda();});
+ }
+ exception.rethrow();
+ }
+
+}
\ No newline at end of file