Removed dataSchedule class

This commit is contained in:
mattijs 2008-05-20 09:28:00 +01:00
parent 14befb8ec4
commit 14a17c6fef
7 changed files with 95 additions and 357 deletions

View File

@ -327,7 +327,6 @@ $(polyBoundaryMesh)/polyBoundaryMesh.C
$(polyBoundaryMesh)/polyBoundaryMeshEntries.C
meshes/ProcessorTopology/commSchedule.C
meshes/ProcessorTopology/dataSchedule.C
globalMeshData = $(polyMesh)/globalMeshData
$(globalMeshData)/globalMeshData.C

View File

@ -1,149 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "dataSchedule.H"
#include "SortableList.H"
#include "commSchedule.H"
#include "Pstream.H"
#include "HashSet.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(dataSchedule, 0);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct from separate addressing
Foam::dataSchedule::dataSchedule
(
const labelList& sendProcs,
const labelList& receiveProcs
)
:
sendOrder_(Pstream::nProcs()),
receiveOrder_(Pstream::nProcs())
{
// Determine the schedule
// ~~~~~~~~~~~~~~~~~~~~~~
// Get all pairs of processors. Leave out local comms.
List<labelPair> allComms;
{
HashSet<labelPair, labelPair::Hash<> > commsSet(Pstream::nProcs());
forAll(receiveProcs, i)
{
if (sendProcs[i] != receiveProcs[i])
{
commsSet.insert(labelPair(sendProcs[i], receiveProcs[i]));
}
}
allComms = commsSet.toc();
}
// Determine my schedule.
labelList mySchedule
(
commSchedule
(
Pstream::nProcs(),
allComms
).procSchedule()[Pstream::myProcNo()]
);
// Processors involved in my schedule
List<labelPair>::operator=
(
IndirectList<labelPair>(allComms, mySchedule)
);
if (debug)
{
Pout<< "I need to:" << endl;
forAll(*this, i)
{
const labelPair& twoProcs = operator[](i);
label sendProc = twoProcs[0];
label recvProc = twoProcs[1];
if (recvProc == Pstream::myProcNo())
{
Pout<< " receive from " << sendProc << endl;
}
else
{
Pout<< " send to " << recvProc << endl;
}
}
}
// Determine the addressing
// ~~~~~~~~~~~~~~~~~~~~~~~~
// Per processor the indices we have to send/receive.
List<DynamicList<label> > dynSendOrder(Pstream::nProcs());
List<DynamicList<label> > dynReceiveOrder(Pstream::nProcs());
// Estimate size
forAll(dynSendOrder, procI)
{
dynSendOrder[procI].setSize(sendProcs.size()/Pstream::nProcs());
dynReceiveOrder[procI].setSize(sendProcs.size()/Pstream::nProcs());
}
forAll(sendProcs, sampleI)
{
// Note that also need to include local communication (both receiveProc
// and sendProc on local processor)
if (Pstream::myProcNo() == sendProcs[sampleI])
{
// I am the sender
dynSendOrder[receiveProcs[sampleI]].append(sampleI);
}
if (Pstream::myProcNo() == receiveProcs[sampleI])
{
// I am the receiver
dynReceiveOrder[sendProcs[sampleI]].append(sampleI);
}
}
forAll(dynSendOrder, procI)
{
sendOrder_[procI].transfer(dynSendOrder[procI].shrink());
receiveOrder_[procI].transfer(dynReceiveOrder[procI].shrink());
}
}
// ************************************************************************* //

View File

@ -1,188 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::dataSchedule
Description
Gets for every data item the source processor and the send processor.
Determines:
- which processor do I need to send to / receive from
- what are the indices into the data I need to send / I am receiving.
Example:
- we have global sampling points
- for every sampling point we have the cell/processor containing the point
(sampleCells, sampleCellProcs)
- for every sampling point we also have the destination cell/processor
(receiveCells, receiveCellProcs)
- sampleCellProcs, receiveCellProcs have to be the same on all processors!
then we construct dataSchedule:
@code
dataSchedule mySchedule(sampleCellProcs, receiveCellProcs);
const labelListList& sendOrder = mySchedule.sendOrder();
const labelListList& receiveOrder = mySchedule.receiveOrder();
// Do all remote data
// ~~~~~~~~~~~~~~~~~~
forAll(mySchedule, commI)
{
const labelPair& twoProcs = mySchedule[i];
label sendProc = twoProcs[0];
label recvProc = twoProcs[1];
if (Pstream::myProcNo() == sendProc)
{
// I am sender. Send to recvProc.
// Labels of my cells to sample
labelList cellLabels
(
IndirectList<label>(sampleCells, sendOrder[recvProc])
);
OPstream toProc(recvProc);
toProc<< IndirectList<vector>(fld, cellLabels)();
}
else
{
// I am receiver. Receive from sendProc.
IPstream fromProc(sendProc);
vectorField fromFld(fromProc);
// Destination cells
labelList cellLabels
(
IndirectList<label>(receiveCells, receiveOrder[sendProc])
);
forAll(fromFld, i)
{
fld[cellLabels[i]] = fromFld[i];
}
}
}
// Do local data
// ~~~~~~~~~~~~~
labelList sendCells
(
IndirectList<label>(sampleCells, sendOrder[Pstream::myProcNo()])
);
vectorField toMyself(IndirectList<vector>(fld, sendCells)());
// Destination cells
labelList recvCells
(
IndirectList<label>
(
patchFaces,
receiveOrder[Pstream::myProcNo()]
)
);
forAll(toMyself, i)
{
recvCells[i] = toMySelf[i];
}
@endcode
SourceFiles
dataSchedule.C
\*---------------------------------------------------------------------------*/
#ifndef dataSchedule_H
#define dataSchedule_H
#include "commSchedule.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class dataSchedule Declaration
\*---------------------------------------------------------------------------*/
class dataSchedule
:
public List<labelPair>
{
// Private data
//- Per processor to send to the order in which the data needs to
// be packed.
labelListList sendOrder_;
//- Per processor to receive from the order how to unpack the
// received data.
labelListList receiveOrder_;
public:
ClassName("dataSchedule");
// Constructors
//- Construct from components
dataSchedule(const labelList& sendProcs, const labelList& receiveProcs);
// Member Functions
//- Send order per processor
const labelListList& sendOrder() const
{
return sendOrder_;
}
//- Receive order per processor
const labelListList& receiveOrder() const
{
return receiveOrder_;
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -185,6 +185,78 @@ Foam::mapDistribute::mapDistribute
{}
Foam::mapDistribute::mapDistribute
(
const labelList& sendProcs,
const labelList& recvProcs
)
:
constructSize_(sendProcs.size()),
schedulePtr_()
{
if (sendProcs.size() != recvProcs.size())
{
FatalErrorIn
(
"mapDistribute::mapDistribute(const labelList&, const labelList&)"
) << "The send and receive data is not the same length. sendProcs:"
<< sendProcs.size() << " recvProcs:" << recvProcs.size()
<< abort(FatalError);
}
// Per processor the number of samples we have to send/receive.
labelList nSend(Pstream::nProcs(), 0);
labelList nRecv(Pstream::nProcs(), 0);
forAll(sendProcs, sampleI)
{
label sendProc = sendProcs[sampleI];
label recvProc = recvProcs[sampleI];
// Note that also need to include local communication (both
// RecvProc and sendProc on local processor)
if (Pstream::myProcNo() == sendProc)
{
// I am the sender. Count destination processor.
nSend[recvProc]++;
}
if (Pstream::myProcNo() == recvProc)
{
// I am the receiver.
nRecv[sendProc]++;
}
}
subMap_.setSize(Pstream::nProcs());
constructMap_.setSize(Pstream::nProcs());
forAll(nSend, procI)
{
subMap_[procI].setSize(nSend[procI]);
constructMap_[procI].setSize(nRecv[procI]);
}
nSend = 0;
nRecv = 0;
forAll(sendProcs, sampleI)
{
label sendProc = sendProcs[sampleI];
label recvProc = recvProcs[sampleI];
if (Pstream::myProcNo() == sendProc)
{
// I am the sender. Store index I need to send.
subMap_[recvProc][nSend[recvProc]++] = sampleI;
}
if (Pstream::myProcNo() == recvProc)
{
// I am the receiver.
constructMap_[sendProc][nRecv[sendProc]++] = sampleI;
}
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //

View File

@ -111,6 +111,14 @@ public:
const bool reUse // clone or reuse
);
//- Construct from reverse addressing: per data item the send
// processor and the receive processor. All processors get same data.
mapDistribute
(
const labelList& sendProcs,
const labelList& recvProcs
);
// Member Functions

View File

@ -26,9 +26,9 @@ License
#include "directMappedPolyPatch.H"
#include "addToRunTimeSelectionTable.H"
#include "polyMesh.H"
#include "ListListOps.H"
#include "meshSearch.H"
#include "mapDistribute.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -217,26 +217,22 @@ void Foam::directMappedPolyPatch::calcMapping() const
// - cell sample is in (so source when mapping)
// sampleCells, sampleCellProcs.
// Determine schedule.
mapDistribute distMap(sampleCellProcs, patchFaceProcs);
// Determine the schedule
// ~~~~~~~~~~~~~~~~~~~~~~
// Rework the schedule to cell data to send, face data to receive.
schedulePtr_.reset(new List<labelPair>(distMap.schedule()));
dataSchedule mySchedule(sampleCellProcs, patchFaceProcs);
// Extract the scedule itself (reuse storage)
schedulePtr_.reset(new List<labelPair>(mySchedule, true));
const labelListList& sendOrder = mySchedule.sendOrder();
const labelListList& receiveOrder = mySchedule.receiveOrder();
const labelListList& subMap = distMap.subMap();
const labelListList& constructMap = distMap.constructMap();
// Extract the particular data I need to send and receive.
sendCellLabelsPtr_.reset(new labelListList(sendOrder.size()));
sendCellLabelsPtr_.reset(new labelListList(subMap.size()));
labelListList& sendCellLabels = sendCellLabelsPtr_();
forAll(sendOrder, procI)
forAll(subMap, procI)
{
sendCellLabels[procI] =
IndirectList<label>(sampleCells, sendOrder[procI]);
sendCellLabels[procI] = IndirectList<label>(sampleCells, subMap[procI]);
if (debug)
{
@ -245,13 +241,13 @@ void Foam::directMappedPolyPatch::calcMapping() const
}
}
receiveFaceLabelsPtr_.reset(new labelListList(receiveOrder.size()));
receiveFaceLabelsPtr_.reset(new labelListList(constructMap.size()));
labelListList& receiveFaceLabels = receiveFaceLabelsPtr_();
forAll(receiveOrder, procI)
forAll(constructMap, procI)
{
receiveFaceLabels[procI] =
IndirectList<label>(patchFaces, receiveOrder[procI]);
IndirectList<label>(patchFaces, constructMap[procI]);
if (debug)
{

View File

@ -41,7 +41,7 @@ SourceFiles
#define directMappedPolyPatch_H
#include "polyPatch.H"
#include "dataSchedule.H"
#include "labelPair.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -64,7 +64,7 @@ class directMappedPolyPatch
// Derived information
//- Communication schedule
//- Communication schedule.
mutable autoPtr<List<labelPair> > schedulePtr_;
//- Cells to sample per processor