OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

PstreamReduceOps.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #ifndef PstreamReduceOps_H
00028 #define PstreamReduceOps_H
00029 
00030 #include "Pstream.H"
00031 #include "ops.H"
00032 
00033 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00034 
00035 namespace Foam
00036 {
00037 
00038 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00039 
00040 // Reduce operation with user specified communication schedule
00041 template <class T, class BinaryOp>
00042 void reduce
00043 (
00044     const List<Pstream::commsStruct>& comms,
00045     T& Value,
00046     const BinaryOp& bop
00047 )
00048 {
00049     Pstream::gather(comms, Value, bop);
00050     Pstream::scatter(comms, Value);
00051 }    
00052 
00053 
00054 // Reduce using either linear or tree communication schedule
00055 template <class T, class BinaryOp>
00056 void reduce
00057 (
00058     T& Value,
00059     const BinaryOp& bop
00060 )
00061 {
00062     if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
00063     {
00064         reduce(Pstream::linearCommunication(), Value, bop);
00065     }
00066     else
00067     {
00068         reduce(Pstream::treeCommunication(), Value, bop);
00069     }
00070 }    
00071 
00072 
00073 // Reduce using either linear or tree communication schedule
00074 template <class T, class BinaryOp>
00075 T returnReduce
00076 (
00077     const T& Value,
00078     const BinaryOp& bop
00079 )
00080 {
00081     T WorkValue(Value);
00082 
00083     if (Pstream::nProcs() < Pstream::nProcsSimpleSum)
00084     {
00085         reduce(Pstream::linearCommunication(), WorkValue, bop);
00086     }
00087     else
00088     {
00089         reduce(Pstream::treeCommunication(), WorkValue, bop);
00090     }
00091 
00092     return WorkValue;
00093 }    
00094 
00095 
00096 // Insist there is a specialisation for the reduction of a scalar
00097 void reduce(scalar& Value, const sumOp<scalar>& bop);
00098 
00099 
00100 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00101 
00102 } // End namespace Foam
00103 
00104 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00105 
00106 #endif
00107 
00108 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd