MPI particle id handler
This commit is contained in:
parent
5f90605a41
commit
6241fa6dd3
|
@ -0,0 +1,70 @@
|
|||
#include "MPIParticleIdHandler.hpp"
|
||||
#include "procCommunication.hpp"
|
||||
|
||||
pFlow::MPI::MPIParticleIdHandler::MPIParticleIdHandler
|
||||
(
|
||||
pointStructure& pStruct
|
||||
)
|
||||
:
|
||||
particleIdHandler(pStruct)
|
||||
{
|
||||
initialIdCheck();
|
||||
}
|
||||
|
||||
pFlow::Pair<pFlow::uint32, pFlow::uint32>
|
||||
pFlow::MPI::MPIParticleIdHandler::getIdRange(uint32 nNewParticles)
|
||||
{
|
||||
uint32 startId;
|
||||
if(maxId_==-1)
|
||||
{
|
||||
startId = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
startId = maxId_+1;
|
||||
}
|
||||
uint32 endId = startId+nNewParticles-1;
|
||||
maxId_ = endId;
|
||||
return {startId, endId};
|
||||
}
|
||||
|
||||
bool pFlow::MPI::MPIParticleIdHandler::initialIdCheck()
|
||||
{
|
||||
/// empty point structure / no particles in simulation
|
||||
uint32 maxId = -1;
|
||||
if( !pStruct().empty() )
|
||||
{
|
||||
maxId = max( *this );
|
||||
}
|
||||
|
||||
auto maxIdAll = procVector<uint32>(pFlowProcessors());
|
||||
auto numAll = procVector<uint32>(pFlowProcessors());
|
||||
auto comm = procCommunication(pFlowProcessors());
|
||||
|
||||
comm.collectAllToAll(maxId, maxIdAll);
|
||||
comm.collectAllToAll(size(),numAll);
|
||||
|
||||
uint32 n = 0;
|
||||
for(uint32 i=0; i<maxIdAll.size(); i++)
|
||||
{
|
||||
if( maxIdAll[i]==-1 && numAll[i]!= 0)
|
||||
{
|
||||
if(comm.localRank() == i)
|
||||
{
|
||||
fillSequence(*this, n);
|
||||
maxId_ = size()-1 + n;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if(comm.localRank() == i)
|
||||
{
|
||||
maxId_ = maxIdAll[i];
|
||||
}
|
||||
}
|
||||
n += numAll[i];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*------------------------------- phasicFlow ---------------------------------
|
||||
O C enter of
|
||||
O O E ngineering and
|
||||
O O M ultiscale modeling of
|
||||
OOOOOOO F luid flow
|
||||
------------------------------------------------------------------------------
|
||||
Copyright (C): www.cemf.ir
|
||||
email: hamid.r.norouzi AT gmail.com
|
||||
------------------------------------------------------------------------------
|
||||
Licence:
|
||||
This file is part of phasicFlow code. It is a free software for simulating
|
||||
granular and multiphase flows. You can redistribute it and/or modify it under
|
||||
the terms of GNU General Public License v3 or any other later versions.
|
||||
|
||||
phasicFlow is distributed to help others in their research in the field of
|
||||
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
|
||||
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
-----------------------------------------------------------------------------*/
|
||||
#ifndef __MPIParticleIdHandler_hpp__
|
||||
#define __MPIParticleIdHandler_hpp__
|
||||
|
||||
#include "particleIdHandler.hpp"
|
||||
|
||||
namespace pFlow::MPI
|
||||
{
|
||||
|
||||
class MPIParticleIdHandler : public particleIdHandler
|
||||
{
|
||||
private:
|
||||
|
||||
uint32 maxId_ = -1;
|
||||
|
||||
bool initialIdCheck() override;
|
||||
|
||||
public:
|
||||
|
||||
ClassInfo("particleIdHandler<MPI>");
|
||||
|
||||
explicit MPIParticleIdHandler(pointStructure& pStruct);
|
||||
|
||||
~MPIParticleIdHandler() override = default;
|
||||
|
||||
add_vCtor(
|
||||
particleIdHandler,
|
||||
MPIParticleIdHandler,
|
||||
pointStructure
|
||||
);
|
||||
|
||||
Pair<uint32, uint32> getIdRange(uint32 nNewParticles) override;
|
||||
|
||||
uint32 maxId() const override
|
||||
{
|
||||
return maxId_;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //__MPIParticleIdHandler_hpp__
|
Loading…
Reference in New Issue