From 38962fffd3ee86d2701fe2b0a5fd9e0cfce95f5d Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Wed, 28 Oct 2015 09:00:05 +0100
Subject: [PATCH] openmp -> C++11 threads in non-global fit loop

---
 pub/lib/fit.cpp | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/pub/lib/fit.cpp b/pub/lib/fit.cpp
index a52ff20f..5c5ff649 100644
--- a/pub/lib/fit.cpp
+++ b/pub/lib/fit.cpp
@@ -9,6 +9,7 @@
 
 #include "defs.hpp"
 
+#include <thread>
 #include <boost/format.hpp>
 #include <omp.h>
 #include <lmmin.h>
@@ -502,18 +503,17 @@ void NCurveFit::fit( bool _allow_slow_conv )
             for ( int j=0; j<fc->nJ(); j++ )
                 if ( !fc->VC(j)->frozen )
                     J.push_back( j );
-            int jout=0; // to report on
             vector<string> out(J.size(), "");
-#pragma omp parallel for if ( !verbosity )
+            vector<std::thread> workers;
             for ( int jj=0; jj<J.size(); ++jj ) {
-                out[J[jj]] = fit_one_spec( fc, fd, fiter.k(), J[jj], control ) + "\n";
-#pragma omp critical
-                { // report results in regular order
-                    if ( J[jj]==jout )
-                        while( jout<J.size() && out[jout]!="" )
-                            cout << out[jout++];
-                }
-            } // j
+                workers.push_back( std::thread([&](int _jj) -> void {
+                            out[_jj] = fit_one_spec( fc, fd, fiter.k(), J[_jj], control ) +
+                                "\n"; }, jj ) );
+            }
+            for ( int jj=0; jj<J.size(); ++jj ) {
+                workers[jj].join();
+                cout << out[jj];
+            }
         } // fit mode
     } // k
 }
-- 
GitLab