ppap4lmp  0.7.2
inv_omp.cpp
Go to the documentation of this file.
1 
9 #include "inv_omp.h"
10 #include "../utils/message.h"
11 
12 namespace ut = utils;
13 
14 /* ------------------------------------------------------------------ */
15 
17 {
18  #ifdef _OPENMP
19  ut::log(
20  "Max number of threads = " + std::to_string(omp_get_max_threads()));
21  #endif
22 
23  Str error_msg;
24 
25  #pragma omp parallel
26  {
27  while (error_msg.empty())
28  {
29  try
30  {
31  bool finish_loop = true;
32 
33  for (const auto &p : procs)
34  {
35  /* NOTE:
36  Exit the while loop when all the processors have finished
37  thier computation.
38  */
39  finish_loop &= p->run();
40  }
41 
42  if (finish_loop) break;
43  }
44  // NOTE: Exception must be caught in the same scope.
45  catch (std::runtime_error &e)
46  {
47  #pragma omp critical (inv_omp)
48  {
49  /* NOTE:
50  Older error messages might be overwritten by newer one.
51  */
52  error_msg = e.what();
53  }
54 
55  break;
56  }
57  }
58  }
59 
60  if (!error_msg.empty())
61  {
62  throw std::runtime_error(error_msg);
63  }
64 }
std::string Str
Str is an alias for string.
Definition: std.h:21
This file has a definition of InvOMP class, which is a subclass of Invoker class. ...
std::vector< T > Vec
Vec is an alias for vector (same as list in Python).
Definition: std.h:27
void runtime_error(const Str &msg)
Raise (for Python) and throw (for C++) a runtime error.
void log(const Str &msg)
Logging a message.
Definition: message.cpp:29
Namespace for utility functions.
Definition: join.h:14
std::shared_ptr< T > ShPtr
ShPtr is an alias for shared pointer.
Definition: std.h:16
virtual void execute_impl(const Vec< ShPtr< Processor >> &procs) override
This method overrides Invoker::execute_impl.
Definition: inv_omp.cpp:16