Commit d88bc072 authored by mattijs's avatar mattijs
Browse files

schedule calculation; skipping unused procs

parent b0e8eaf6
......@@ -31,7 +31,11 @@ License
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::mapDistribute::calcSchedule() const
Foam::List<Foam::labelPair> Foam::mapDistribute::schedule
(
const labelListList& subMap,
const labelListList& constructMap
)
{
// Communications: send and receive processor
List<labelPair> allComms;
......@@ -40,16 +44,16 @@ void Foam::mapDistribute::calcSchedule() const
HashSet<labelPair, labelPair::Hash<> > commsSet(Pstream::nProcs());
// Find what communication is required
forAll(subMap_, procI)
forAll(subMap, procI)
{
if (procI != Pstream::myProcNo())
{
if (subMap_[procI].size() > 0)
if (subMap[procI].size() > 0)
{
// I need to send to procI
commsSet.insert(labelPair(Pstream::myProcNo(), procI));
}
if (constructMap_[procI].size() > 0)
if (constructMap[procI].size() > 0)
{
// I need to receive from procI
commsSet.insert(labelPair(procI, Pstream::myProcNo()));
......@@ -120,13 +124,7 @@ void Foam::mapDistribute::calcSchedule() const
);
// Processors involved in my schedule
schedulePtr_.reset
(
new List<labelPair>
(
IndirectList<labelPair>(allComms, mySchedule)
)
);
return IndirectList<labelPair>(allComms, mySchedule);
//if (debug)
......@@ -152,6 +150,22 @@ void Foam::mapDistribute::calcSchedule() const
}
const Foam::List<Foam::labelPair>& Foam::mapDistribute::schedule() const
{
if (!schedulePtr_.valid())
{
schedulePtr_.reset
(
new List<labelPair>
(
schedule(subMap_, constructMap_)
)
);
}
return schedulePtr_();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
//- Construct from components
......@@ -257,13 +271,4 @@ Foam::mapDistribute::mapDistribute
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
// ************************************************************************* //
......@@ -36,6 +36,8 @@ Note:
Schedule is a list of processor pairs (one send, one receive. One of
them will be myself) which forms a scheduled (i.e. non-buffered) exchange.
See distribute on how to use it.
Note2: number of items send on one processor have to equal the number
of items received on the other processor.
SourceFiles
......@@ -80,8 +82,6 @@ class mapDistribute
// Private Member Functions
void calcSchedule() const;
//- Disallow default bitwise copy construct
mapDistribute(const mapDistribute&);
......@@ -142,15 +142,15 @@ public:
return constructMap_;
}
//- Calculate a schedule. See above.
static List<labelPair> schedule
(
const labelListList& subMap,
const labelListList& constructMap
);
//- Return a schedule. Demand driven. See above.
const List<labelPair>& schedule() const
{
if (!schedulePtr_.valid())
{
calcSchedule();
}
return schedulePtr_();
}
const List<labelPair>& schedule() const;
// Other
......
......@@ -48,15 +48,28 @@ void Foam::mapDistribute::distribute
// Send sub field to neighbour
for (label domain = 0; domain < Pstream::nProcs(); domain++)
{
if (domain != Pstream::myProcNo())
const labelList& map = subMap[domain];
if (domain != Pstream::myProcNo() && map.size() > 0)
{
List<T> subField(map.size());
forAll(map, i)
{
subField[i] = field[map[i]];
}
OPstream toNbr(Pstream::blocking, domain);
toNbr << IndirectList<T>(field, subMap[domain])();
toNbr << subField;
}
}
// Subset myself
List<T> subField(IndirectList<T>(field, subMap[Pstream::myProcNo()]));
const labelList& mySubMap = subMap[Pstream::myProcNo()];
List<T> subField(mySubMap.size());
forAll(mySubMap, i)
{
subField[i] = field[mySubMap[i]];
}
// Receive sub field from myself (subField)
const labelList& map = constructMap[Pstream::myProcNo()];
......@@ -71,7 +84,11 @@ void Foam::mapDistribute::distribute
// Receive sub field from neighbour
for (label domain = 0; domain < Pstream::nProcs(); domain++)
{
if (domain != Pstream::myProcNo())
if
(
domain != Pstream::myProcNo()
&& constructMap[domain].size() > 0
)
{
IPstream fromNbr(Pstream::blocking, domain);
List<T> subField(fromNbr);
......@@ -93,7 +110,13 @@ void Foam::mapDistribute::distribute
List<T> newField(constructSize);
// Subset myself
List<T> subField(IndirectList<T>(field, subMap[Pstream::myProcNo()]));
const labelList& mySubMap = subMap[Pstream::myProcNo()];
List<T> subField(mySubMap.size());
forAll(mySubMap, i)
{
subField[i] = field[mySubMap[i]];
}
// Receive sub field from myself (subField)
const labelList& map = constructMap[Pstream::myProcNo()];
......@@ -112,8 +135,16 @@ void Foam::mapDistribute::distribute
if (Pstream::myProcNo() == sendProc)
{
// I am sender. Send to recvProc.
const labelList& map = subMap[recvProc];
List<T> subField(map.size());
forAll(map, i)
{
subField[i] = field[map[i]];
}
OPstream toNbr(Pstream::scheduled, recvProc);
toNbr << IndirectList<T>(field, subMap[recvProc])();
toNbr << subField;
}
else
{
......@@ -136,7 +167,13 @@ void Foam::mapDistribute::distribute
List<T> newField(constructSize);
// Subset myself
List<T> subField(IndirectList<T>(field, subMap[Pstream::myProcNo()]));
const labelList& mySubMap = subMap[Pstream::myProcNo()];
List<T> subField(mySubMap.size());
forAll(mySubMap, i)
{
subField[i] = field[mySubMap[i]];
}
// Receive sub field from myself (subField)
const labelList& map = constructMap[Pstream::myProcNo()];
......@@ -149,10 +186,19 @@ void Foam::mapDistribute::distribute
// Send sub field to neighbour
for (label domain = 0; domain < Pstream::nProcs(); domain++)
{
if (domain != Pstream::myProcNo())
const labelList& map = subMap[domain];
if (domain != Pstream::myProcNo() && map.size() > 0)
{
List<T> subField(map.size());
forAll(map, i)
{
subField[i] = field[map[i]];
}
OPstream toNbr(Pstream::nonBlocking, domain);
toNbr << IndirectList<T>(field, subMap[domain])();
toNbr << subField;
}
}
......@@ -160,13 +206,13 @@ void Foam::mapDistribute::distribute
// Receive sub field from neighbour
for (label domain = 0; domain < Pstream::nProcs(); domain++)
{
if (domain != Pstream::myProcNo())
const labelList& map = constructMap[domain];
if (domain != Pstream::myProcNo() && map.size() > 0)
{
IPstream fromNbr(Pstream::nonBlocking, domain);
List<T> subField(fromNbr);
const labelList& map = constructMap[domain];
forAll(map, i)
{
newField[map[i]] = subField[i];
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment