FreeFOAM The Cross-Platform CFD Toolkit
PstreamImpl.C
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*\
2  ______ _ ____ __ __
3  | ____| _| |_ / __ \ /\ | \/ |
4  | |__ _ __ ___ ___ / \| | | | / \ | \ / |
5  | __| '__/ _ \/ _ ( (| |) ) | | |/ /\ \ | |\/| |
6  | | | | | __/ __/\_ _/| |__| / ____ \| | | |
7  |_| |_| \___|\___| |_| \____/_/ \_\_| |_|
8 
9  FreeFOAM: The Cross-Platform CFD Toolkit
10 
11  Copyright (C) 2008-2012 Michael Wild <themiwi@users.sf.net>
12  Gerber van der Graaf <gerber_graaf@users.sf.net>
13 --------------------------------------------------------------------------------
14 License
15  This file is part of FreeFOAM.
16 
17  FreeFOAM is free software: you can redistribute it and/or modify it
18  under the terms of the GNU General Public License as published by the
19  Free Software Foundation, either version 3 of the License, or (at your
20  option) any later version.
21 
22  FreeFOAM is distributed in the hope that it will be useful, but WITHOUT
23  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
24  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25  for more details.
26 
27  You should have received a copy of the GNU General Public License
28  along with FreeFOAM. If not, see <http://www.gnu.org/licenses/>.
29 
30 \*----------------------------------------------------------------------------*/
31 
32 #include <OpenFOAM/PstreamImpl.H>
33 #include <OpenFOAM/Pstream.H>
34 #include <OpenFOAM/debug.H>
35 #include <OpenFOAM/OSspecific.H>
36 #include <OpenFOAM/dictionary.H>
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
43 
44 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
45 
46 Foam::autoPtr<Foam::PstreamImpl> Foam::PstreamImpl::instance_;
47 
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 
50 void Foam::PstreamImpl::setParRun(bool& isParallel)
51 {
52  isParallel = true;
53 
54  Pout.prefix() = '[' + name(Pstream::myProcNo()) + "] ";
55  Perr.prefix() = '[' + name(Pstream::myProcNo()) + "] ";
56 }
57 
58 
60 {
61  Pstream::initCommunicationSchedule();
62 }
63 
64 // * * * * * * * * * * * * * Local Helper Functions * * * * * * * * * * * * //
65 
66 // helper function to find the config section name
68 {
69  // check FREEFOAM_PSTREAM_CONFIG
70  if(env("FREEFOAM_PSTREAM_CONFIG"))
71  {
72  return getEnv("FREEFOAM_PSTREAM_CONFIG");
73  }
74  else if(debug::controlDict().found("PstreamImplementation"))
75  {
76  // check the global controlDict::PstreamImplementation::configName
77  word configName;
78  debug::controlDict().subDict("PstreamImplementation").lookup("configName") >> configName;
79  return configName;
80  }
81  else
82  {
83  // otherwise return empty
84  return word();
85  }
86 }
87 
88 // * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * * //
89 
91 {
92  if(!instance_.valid())
93  {
94  // load the Pstream library the user wants to use
95  loadPstreamLibrary();
96  // find the Pstream type the user wants to use
97  instance_ = loadPstreamInstance<PstreamImpl>
98  (
99  "Pstream",
100  "FREEFOAM_PSTREAM_CLASS",
101  dictionaryConstructorTablePtr_
102  );
103  }
104  return instance_;
105 }
106 
108 {
109  static bool didLoad = false;
110  if(!didLoad)
111  {
112  fileName PstreamLibName;
113  // check whether FREEFOAM_PSTREAM_LIBRARY is set
114  if(env("FREEFOAM_PSTREAM_LIBRARY"))
115  {
116  PstreamLibName = getEnv("FREEFOAM_PSTREAM_LIBRARY");
117  }
118  else
119  {
120  // otherwise check the global controlDict
121  word configName = PstreamConfigSectionName();
122  if
123  (
124  !configName.empty() &&
125  debug::controlDict().subDict("PstreamImplementation")
126  .subDict(configName).found("library")
127  )
128  {
129  debug::controlDict().subDict("PstreamImplementation")
130  .subDict(configName).lookup("library") >> PstreamLibName;
131  }
132  }
133 
134  // if we found some Pstream library, load it, otherwise assume it is
135  // not necessary
136  if(!PstreamLibName.empty())
137  {
138  if(PstreamImpl::debug)
139  {
140  Info<< "Trying to load Pstream library '" << PstreamLibName << "'" << endl;
141  }
142 
143  if(!dlLibraryTable::open(PstreamLibName))
144  {
146  (
147  "PstreamImpl::loadPstreamLibrary()"
148  ) << "Failed to load the library '" << PstreamLibName << "'" << endl
150  }
151  }
152  else
153  {
154  if(PstreamImpl::debug)
155  {
156  WarningIn
157  (
158  "PstreamImpl::loadPstreamLibrary()"
159  ) << "No Pstream library specified to load" << endl;
160  }
161  }
162  didLoad = true;
163  }
164 }
165 
166 // ************************ vim: set sw=4 sts=4 et: ************************ //