OpenFOAM logo
Open Source CFD Toolkit

commSchedule.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-2005 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 Class
00026     commSchedule
00027 
00028 Description
00029     Given the processor topology works out a non-blocking communication
00030     schedule. Instead of doing all sends first and having a lot of buffering
00031     this works out how to have each processor do a sequence of sends and
00032     receives such that there can never be the case that two processors are
00033     waiting for each other to send something.
00034 
00035     *this[procI] is for processor procI a list with for every iteration
00036     the neighbour it has to communicate with. It does not prespecify which
00037     half should start sending or receiving. You might want to group the two
00038     close together or separate them in time as long as one is sending and the
00039     other is receiving.
00040 
00041 
00042     A typical use with matched send and receives is something like:
00043 
00044     const labelList& mySchedule = operator[](Pstream::myProcNo()];
00045 
00046     forAll(mySchedule, iterI)
00047     {
00048         label nb = mySchedule[iterI];
00049 
00050         if (nb < Pstream::myProcNo())
00051         {
00052             // Send to neighbour
00053             ..
00054             // Receive from neighbour
00055             ..
00056         }
00057         else
00058         {
00059             // Receive from neighbour
00060             ..
00061             // Send to neighbour
00062             ..
00063         }
00064     }
00065     
00066 
00067 
00068 SourceFiles
00069     commSchedule.C
00070 
00071 \*---------------------------------------------------------------------------*/
00072 
00073 #ifndef commSchedule_H
00074 #define commSchedule_H
00075 
00076 #include "labelList.H"
00077 #include "boolList.H"
00078 
00079 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00080 
00081 namespace Foam
00082 {
00083 
00084 /*---------------------------------------------------------------------------*\
00085                            Class commSchedule Declaration
00086 \*---------------------------------------------------------------------------*/
00087 
00088 class commSchedule
00089 :
00090     public labelListList
00091 {
00092     // Private data
00093 
00094         //- Schedule per face. Gives for each face whether communication
00095         //  takes place. Is -1 or the iteration in which communication should
00096         //  take place. *this is the same information but sorted per iteration.
00097         labelList faceSchedule_;
00098 
00099 
00100     // Private Member Functions
00101 
00102         //- Count number of 'busy' neighbouring processors
00103         label nBusyNbs
00104         (
00105             const labelListList& cellFaces,
00106             const labelListList& faceCells,
00107             const boolList& busy,
00108             const label cellI
00109         ) const;
00110 
00111         //- Find faces which are not yet used in a schedule and
00112         //  assign them to the current schedule such that a cell is only
00113         //  used once. Returns true if any faces have been 'scheduled', false
00114         //  otherwise
00115         bool scheduleIteration
00116         (
00117             const labelListList& cellFaces,
00118             const labelListList& faceCells,
00119             const label commIter
00120         );
00121 
00122         //- Schedule all. Fill faceSchedule_ and *this
00123         void scheduleAll
00124         (
00125             const labelListList& cellFaces,
00126             const labelListList& faceCells
00127         );
00128 
00129 
00130 public:
00131 
00132     // Constructors
00133 
00134         //- Construct from addressing
00135         commSchedule
00136         (
00137             const labelListList& cellFaces,
00138             const labelListList& faceCells
00139         );
00140 
00141 
00142     // Member Functions
00143 
00144         //- Schedule on a face by face basis.
00145         const labelList& faceSchedule() const
00146         {
00147             return faceSchedule_;
00148         }
00149 };
00150 
00151 
00152 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00153 
00154 } // End namespace Foam
00155 
00156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00157 
00158 #endif
00159 
00160 // ************************************************************************* //
For further information go to www.openfoam.org