From bee3cb138a6056a523df07570b6de6292157e373 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@uliege.be>
Date: Tue, 24 May 2022 08:39:09 +0200
Subject: [PATCH] skip remaining operations if exception is raised during a
 #pragma omp for

---
 src/geo/GModelIO_MSH4.cpp   | 1 +
 src/mesh/Generator.cpp      | 2 ++
 src/mesh/meshGRegionHxt.cpp | 1 +
 3 files changed, 4 insertions(+)

diff --git a/src/geo/GModelIO_MSH4.cpp b/src/geo/GModelIO_MSH4.cpp
index 54222d9a17..eed1b08c2f 100644
--- a/src/geo/GModelIO_MSH4.cpp
+++ b/src/geo/GModelIO_MSH4.cpp
@@ -2851,6 +2851,7 @@ int GModel::_writePartitionedMSH4(const std::string &baseName, double version,
   bool exceptions = false;
 #pragma omp parallel for num_threads(nthreads)
   for(std::size_t part = 1; part <= getNumPartitions(); part++) {
+    if(exceptions) continue;
     std::ostringstream sstream;
     sstream << baseName << "_" << part << ".msh";
     if(getNumPartitions() > 100) {
diff --git a/src/mesh/Generator.cpp b/src/mesh/Generator.cpp
index 5f87235687..808fda31a7 100644
--- a/src/mesh/Generator.cpp
+++ b/src/mesh/Generator.cpp
@@ -383,6 +383,7 @@ static void Mesh1D(GModel *m)
     bool exceptions = false;
 #pragma omp parallel for schedule(dynamic) num_threads(nthreads)
     for(size_t K = 0; K < temp.size(); K++) {
+      if(exceptions) continue;
       int localPending = 0;
       GEdge *ed = temp[K];
       if(ed->meshStatistics.status == GEdge::PENDING) {
@@ -538,6 +539,7 @@ static void Mesh2D(GModel *m)
       temp.insert(temp.begin(), f.begin(), f.end());
 #pragma omp parallel for schedule(dynamic) num_threads(nthreads)
       for(size_t K = 0; K < temp.size(); K++) {
+        if(exceptions) continue;
         int localPending = 0;
         if(temp[K]->meshStatistics.status == GFace::PENDING) {
           backgroundMesh::current()->unset();
diff --git a/src/mesh/meshGRegionHxt.cpp b/src/mesh/meshGRegionHxt.cpp
index f45064bf0c..7030a4cdda 100644
--- a/src/mesh/meshGRegionHxt.cpp
+++ b/src/mesh/meshGRegionHxt.cpp
@@ -59,6 +59,7 @@ static HXTStatus nodalSizesCallBack(double *pts, uint32_t *volume,
   bool exceptions = false;
 #pragma omp parallel for schedule(dynamic) num_threads(nthreads)
   for(size_t i = 0; i < numPts; i++) {
+    if(exceptions) continue;
     if(volume[i] < 0 || volume[i] >= allGR->size()) {
       Msg::Error("Invalid volume tag %d in mesh size calculation", volume[i]);
       continue;
-- 
GitLab