GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
MultiThreadedProcess.hpp
Go to the documentation of this file.
1 // This file is part of GranOO, a workbench for DEM simulation.
2 //
3 // Author(s) : - Damien Andre IRCER/UNILIM, Limoges France
4 // <damien.andre@unilim.fr>
5 // - Jean-luc Charles Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
6 // <jean-luc.charles@ensam.eu>
7 // - Jeremie Girardot Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
8 // <jeremie.girardot@ensam.eu>
9 // - Cedric Hubert LAMIH/UPHF, Valenciennes France
10 // <cedric.hubert@uphf.fr>
11 // - Ivan Iordanoff Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
12 // <ivan.iordanoff@ensam.eu>
13 //
14 // Copyright (C) 2008-2019 D. Andre, JL. Charles, J. Girardot, C. Hubert, I. Iordanoff
15 //
16 // This program is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 // This program is distributed in the hope that it will be useful,
22 // but WITHOUT ANY WARRANTY; without even the implied warranty of
23 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 // GNU General Public License for more details.
25 //
26 // You should have received a copy of the GNU General Public License
27 // along with this program. If not, see <http://www.gnu.org/licenses/>.
28 
29 
30 #ifndef _GranOO_libCore_MultiThreadedProcess_hpp_
31 #define _GranOO_libCore_MultiThreadedProcess_hpp_
32 
33 #include <thread>
34 #include <ctime>
35 #include <string>
36 #include <vector>
37 #include <functional>
38 
39 // This is a macro to deal with all multiThreaded Processes in GranOO
40 
41 #include <boost/chrono/thread_clock.hpp>
42 
43 
44 namespace GranOO3
45 {
46  namespace Core
47  {
49  {
50  public:
51  MultiThreadedProcess(const std::string & id = std::string(""));
52  virtual ~MultiThreadedProcess();
53  virtual void parse_xml();
54 
55  // This virtual method must be defined in all PlugIns you want to run on multiple cores (i.e. "GranOO3/PlugIn/ApplyBondLoad.hpp")
56  virtual void run_multi_thread_process(size_t startIndex, size_t stopIndex, size_t threadRank = -1) = 0;
57 
58  void init(size_t totalItemNumberToProcess, bool resetTimeAccumulator = true);
59  void run(size_t totalItemNumberToProcess);
60 
62  unsigned int get_total_number_of_thread() const {return _total_number_of_thread;}
63 
64  private:
65  MultiThreadedProcess(const MultiThreadedProcess &); // Not allowed
66  void operator=(const MultiThreadedProcess &); // Not allowed
67 
68  private:
69  const std::string _ID;
72  std::vector<std::function<void (void)> > _exec_function_vector;
73  };
74 
75  }
76 }
77 
78 #endif
Definition: MultiThreadedProcess.hpp:49
virtual void parse_xml()
Definition: MultiThreadedProcess.cpp:50
size_t _total_item_number_to_process
Definition: MultiThreadedProcess.hpp:70
virtual ~MultiThreadedProcess()
Definition: MultiThreadedProcess.cpp:46
void run(size_t totalItemNumberToProcess)
Definition: MultiThreadedProcess.cpp:85
void operator=(const MultiThreadedProcess &)
virtual void run_multi_thread_process(size_t startIndex, size_t stopIndex, size_t threadRank=-1)=0
void init(size_t totalItemNumberToProcess, bool resetTimeAccumulator=true)
Definition: MultiThreadedProcess.cpp:54
const std::string _ID
Definition: MultiThreadedProcess.hpp:69
std::vector< std::function< void(void)> > _exec_function_vector
Definition: MultiThreadedProcess.hpp:72
MultiThreadedProcess(const MultiThreadedProcess &)
size_t get_total_item_number_to_process() const
Definition: MultiThreadedProcess.hpp:61
unsigned int get_total_number_of_thread() const
Definition: MultiThreadedProcess.hpp:62
MultiThreadedProcess(const std::string &id=std::string(""))
Definition: MultiThreadedProcess.cpp:39
unsigned int _total_number_of_thread
Definition: MultiThreadedProcess.hpp:71
Definition: Common.hpp:198