parRun.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::ParRunControl
26 
27 Description
28  Helper class for initializing parallel jobs from the command arguments.
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #ifndef parRun_H
33 #define parRun_H
34 
35 #include "Pstream.H"
36 #include "IOstreams.H"
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42 
43 /*---------------------------------------------------------------------------*\
44  Class ParRunControl Declaration
45 \*---------------------------------------------------------------------------*/
46 
47 class ParRunControl
48 {
49  bool RunPar;
50 
51 public:
52 
54  :
55  RunPar(false)
56  {}
57 
59  {
60  if (RunPar)
61  {
62  Info<< "Finalising parallel run" << endl;
63  Pstream::exit(0);
64  }
65  }
66 
67  void runPar(int& argc, char**& argv, const bool needsThread)
68  {
69  RunPar = true;
70 
71  if (!Pstream::init(argc, argv, needsThread))
72  {
73  Info<< "Failed to start parallel run" << endl;
74  Pstream::exit(1);
75  }
76  }
77 
78  bool parRun() const
79  {
80  return RunPar;
81  }
82 };
83 
84 
85 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
86 
87 } // End namespace Foam
88 
89 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
90 
91 #endif
92 
93 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void runPar(int &argc, char **&argv, const bool needsThread)
Definition: parRun.H:66
Helper class for initializing parallel jobs from the command arguments.
Definition: parRun.H:46
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
static bool init(int &argc, char **&argv, const bool needsThread)
Initialisation function called from main.
Definition: UPstream.C:35
static void exit(int errnum=1)
Exit program.
Definition: UPstream.C:46
messageStream Info
bool parRun() const
Definition: parRun.H:77
Namespace for OpenFOAM.