FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

PstreamImpl.H

Go to the documentation of this file.
00001 /*----------------------------------------------------------------------------*\
00002                 ______                _     ____          __  __
00003                |  ____|             _| |_  / __ \   /\   |  \/  |
00004                | |__ _ __ ___  ___ /     \| |  | | /  \  | \  / |
00005                |  __| '__/ _ \/ _ ( (| |) ) |  | |/ /\ \ | |\/| |
00006                | |  | | |  __/  __/\_   _/| |__| / ____ \| |  | |
00007                |_|  |_|  \___|\___|  |_|   \____/_/    \_\_|  |_|
00008 
00009                     FreeFOAM: The Cross-Platform CFD Toolkit
00010 
00011   Copyright (C) 2008-2012 Michael Wild <themiwi@users.sf.net>
00012                           Gerber van der Graaf <gerber_graaf@users.sf.net>
00013 --------------------------------------------------------------------------------
00014 License
00015     This file is part of FreeFOAM.
00016 
00017     FreeFOAM is free software: you can redistribute it and/or modify it
00018     under the terms of the GNU General Public License as published by the
00019     Free Software Foundation, either version 3 of the License, or (at your
00020     option) any later version.
00021 
00022     FreeFOAM is distributed in the hope that it will be useful, but WITHOUT
00023     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00024     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00025     for more details.
00026 
00027     You should have received a copy of the GNU General Public License
00028     along with FreeFOAM.  If not, see <http://www.gnu.org/licenses/>.
00029 
00030 Class
00031     Foam::PstreamImpl
00032 
00033 Description
00034     Abstract base class for Pstream operations that depend on the parallel
00035     library used. Foam::PstreamImpl::New will lookup the entry
00036     "PstreamImplementation" in the global controlDict file (i.e. the one
00037     found by Foam::dotFoam) and tries to first load a library named
00038     lib<PstreamImplementation>Pstream.so, and then instantiate the class
00039     <PstreamImplementation>PstreamImpl.
00040 
00041 SourceFiles
00042     PstreamImplI.H
00043     PstreamImpl.C
00044 
00045 
00046 \*----------------------------------------------------------------------------*/
00047 
00048 #ifndef PstreamImpl_H
00049 #define PstreamImpl_H
00050 
00051 #include <OpenFOAM/autoPtr.H>
00052 #include <OpenFOAM/typeInfo.H>
00053 #include <OpenFOAM/runTimeSelectionTables.H>
00054 #include <OpenFOAM/ops.H>
00055 
00056 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00057 
00058 namespace Foam
00059 {
00060 
00061 namespace helper_
00062 {
00063 //- Helper class
00064 struct PstreamBase
00065 {
00066     //- Types of communications
00067     enum commsTypes
00068     {
00069         blocking,
00070         scheduled,
00071         nonBlocking
00072     };
00073 };
00074 } // namespace helper_
00075 
00076 /*---------------------------------------------------------------------------*\
00077                            Class PstreamImpl Declaration
00078 \*---------------------------------------------------------------------------*/
00079 
00080 class PstreamImpl
00081 : public helper_::PstreamBase
00082 {
00083     // Private data
00084 
00085         //- The singleton instance
00086         static autoPtr<PstreamImpl> instance_;
00087 
00088     // Private Member Functions
00089 
00090         //- Disallow default bitwise copy construct
00091         PstreamImpl(const PstreamImpl&);
00092 
00093         //- Disallow default bitwise assignment
00094         void operator=(const PstreamImpl&);
00095 
00096 protected:
00097 
00098     // Protected Member Functions
00099 
00100         //- Set data for parallel running
00101         static void setParRun(bool& isParallel);
00102 
00103         //- Initialize all communication schedules. Callback from
00104         //  PstreamImpl::init()
00105         static void initCommunicationSchedule();
00106 
00107 public:
00108 
00109     //- Types of communications
00110     using helper_::PstreamBase::commsTypes;
00111 
00112     // Declare name of the class and its debug switch
00113     TypeName("PstreamImpl");
00114 
00115     // Declare run-time constructor selection table
00116 
00117         declareRunTimeSelectionTable
00118         (
00119             autoPtr,
00120             PstreamImpl,
00121             dictionary,
00122             (),
00123             ()
00124         );
00125 
00126     // Constructors
00127 
00128         //- Construct null
00129         PstreamImpl(){}
00130 
00131     // Destructor
00132 
00133         virtual ~PstreamImpl() {}
00134 
00135     // Selectors
00136 
00137         //- Return a reference to the selected PstreamImpl implementation
00138         static autoPtr<PstreamImpl> New();
00139 
00140     // Member Functions
00141 
00142         //- Add the valid option this type of communications library
00143         //  adds/requires on the command line
00144         virtual void addValidParOptions(HashTable<string>& validParOptions) = 0;
00145 
00146         //- Initialisation function called from main
00147         //  Spawns slave processes and initialises inter-communication
00148         virtual bool init(int& argc, char**& argv, int& myProcNo, List<int>& procIDs, bool& isParallel) = 0;
00149 
00150         //- Exit program
00151         virtual void exit(int errnum) = 0;
00152 
00153         //- Abort program
00154         virtual void abort() = 0;
00155 
00156         //- Reduce implementation for scalars (@sa PstreamReduceOps.H)
00157         virtual void reduce(scalar& Value, const sumOp<scalar>& bop) = 0;
00158 
00159         //- Loads the Pstream implementation library
00160         static void loadPstreamLibrary();
00161 
00162         //- Loads the given type from the Pstream implementation library
00163         template<class T, class CTable>
00164         static autoPtr<T> loadPstreamInstance
00165         (
00166             const word& dictEntry,
00167             const word& envName,
00168             CTable* ctable
00169         );
00170 
00171 
00172     // Friends
00173 
00174         friend class Pstream;
00175 
00176 };
00177 
00178 
00179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00180 
00181 } // End namespace Foam
00182 
00183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00184 
00185 #include <OpenFOAM/PstreamImplI.H>
00186 
00187 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00188 
00189 #endif
00190 
00191 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines