# PhasicFlow: src/phasicFlow/processors/processors.cpp Source File
PhasicFlow is an open-source parallel DEM (discrete element method) package for simulating granular flow. It is developed in C++ and can be exectued on both GPU (like CUDA) and CPU.

processors.cpp
Go to the documentation of this file.
/*------------------------------- 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.
-----------------------------------------------------------------------------*/
#include "phasicFlowConfig.H"
#ifdef pFlow_Build_MPI
#include "mpiCommunication.hpp"
#endif
// from PhasicFlow
#include "error.hpp"
#include "processors.hpp"
#include "streams.hpp"
#ifdef pFlow_Build_MPI
pFlow::MPI::DataType pFlow::MPI::realx3Type__;
pFlow::MPI::DataType pFlow::MPI::realx4Type__;
pFlow::MPI::DataType pFlow::MPI::int32x3Type__;
pFlow::MPI::DataType pFlow::MPI::uint32x3Type__;
#endif
void pFlow::processors::initProcessors(int argc, char *argv[])
{
#ifdef pFlow_Build_MPI
if(!processors::isInitialized())
{
CheckMPI(MPI_Init(&argc, &argv), true);
initProcessorsCelled_ = true;
argc_ = argc;
argv_ = argv;
MPI_Comm_rank(MPI_COMM_WORLD, &processors::globalRank_);
MPI_Comm_size(MPI_COMM_WORLD, &processors::globalSize_);
if(processors::globalParallel())
{
pFlow::pOutput.activatePrefix();
pFlow::pOutput.setPrefixNum(processors::globalRank_);
pFlow::errReport.activatePrefix();
pFlow::errReport.setPrefixNum(processors::globalRank_);
}
pFlow::mOutput.setMasterSlave(processors::globalMaster());
MPI_Type_contiguous(3, pFlow::MPI::Type<real>(), &pFlow::MPI::realx3Type__);
MPI_Type_commit(&pFlow::MPI::realx3Type__);
MPI_Type_contiguous(4, pFlow::MPI::Type<real>(), &pFlow::MPI::realx4Type__);
MPI_Type_commit(&pFlow::MPI::realx3Type__);
MPI_Type_contiguous(3, pFlow::MPI::Type<int32>(), &pFlow::MPI::int32x3Type__);
MPI_Type_commit(&pFlow::MPI::int32x3Type__);
MPI_Type_contiguous(3, pFlow::MPI::Type<uint32>(), &pFlow::MPI::uint32x3Type__);
MPI_Type_commit(&pFlow::MPI::uint32x3Type__);
}
#else
#endif
}
void pFlow::processors::finalizeProcessors()
{
#ifdef pFlow_Build_MPI
if(initProcessorsCelled_ && !isFinalized())
{
MPI::TypeFree(&pFlow::MPI::realx3Type__);
MPI::TypeFree(&pFlow::MPI::realx4Type__);
MPI::TypeFree(&pFlow::MPI::int32x3Type__);
MPI::TypeFree(&pFlow::MPI::uint32x3Type__);
CheckMPI(MPI_Finalize(), true);
}
#else
#endif
}
pFlow::processors::processors()
{
#ifdef pFlow_Build_MPI
if(globalParallel() && !isInitialized())
{
fatalErrorInFunction<<
"MPI communication is not initialized yet!"<<endl;
processors::abort(MPI_ERR_OP);
}
#endif
}
pFlow::processors::~processors()
{}
bool pFlow::processors::isInitialized()
{
#ifdef pFlow_Build_MPI
int res;
MPI_Initialized(&res);
return res;
#endif
return false;
}
bool pFlow::processors::isFinalized()
{
#ifdef pFlow_Build_MPI
int res;
MPI_Finalized(&res);
return res;
#endif
return false;
}
void pFlow::processors::abort(int error)
{
#ifdef pFlow_Build_MPI
int flag=0;
MPI_Initialized(&flag);
if(flag == 1)
{
MPI_Abort(MPI_COMM_WORLD, error);
MPI_Finalize();
}
exit(error);
#else
exit(error);
#endif
}
bool pFlow::checkMPI(const char* funcName, int error, bool forceAbort, const char* fileName, int lineNumebr)
{
#ifdef pFlow_Build_MPI
if(error == MPI_SUCCESS) return true;
fatalErrorInMessage(funcName, fileName, lineNumebr);
if(!forceAbort) return false;
reportAndExit(error);
return false;
#else
return true;
#endif
}
pFlow::processors::processors
processors()
Constructor.
Definition: processors.cpp:105
pFlow::processors::globalSize_
static int globalSize_
The global size of all processors.
Definition: processors.hpp:65
pFlow::checkMPI
bool checkMPI(const char *funcName, int error, bool forceAbort, const char *fileName, int lineNumebr)
Definition: processors.cpp:165
pFlow::pOutput
processorOstream pOutput
pFlow::processors::initProcessors
static void initProcessors(int argc, char *argv[])
Initialize MPI processors.
Definition: processors.cpp:42
pFlow::processorOstream::activatePrefix
void activatePrefix()
Activate prefix for this stream.
Definition: processorOstream.hpp:83
processors.hpp
pFlow::mOutput
masterOstream mOutput
pFlow::processors::~processors
~processors()
Destructor.
Definition: processors.cpp:119
pFlow::processors::finalizeProcessors
static void finalizeProcessors()
Finalize MPI processors.
Definition: processors.cpp:88
pFlow::processors::globalMaster
static bool globalMaster()
Is this processor the master processor?
Definition: processors.hpp:125
fatalErrorInMessage
pFlow::iOstream & fatalErrorInMessage(const char *fnName, const char *fileName, int linNumber)
Definition: error.cpp:44
pFlow::processors::globalParallel
static bool globalParallel()
Is this a parallel MPI run.
Definition: processors.hpp:98
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
reportAndExit
pFlow::iOstream & reportAndExit(int errorCode)
Definition: error.cpp:111
pFlow::processors::isFinalized
static bool isFinalized()
Is MPI finalized?
Definition: processors.cpp:135
pFlow::errReport
processorOstream errReport
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
CheckMPI
#define CheckMPI(caller, fAbort)
Definition: processors.hpp:39
pFlow::processors::argc
static int argc()
Definition: processors.hpp:145
pFlow::processors::argv
static char ** argv()
Definition: processors.hpp:151
streams.hpp
pFlow::processors::argc_
static int argc_
Definition: processors.hpp:68
pFlow::processorOstream::setPrefixNum
word setPrefixNum(int procNum)
Set processor number to be used in the prefix.
Definition: processorOstream.hpp:76
pFlow::processors::globalRank_
static int globalRank_
Global rank of the current processor.
Definition: processors.hpp:61
pFlow::masterOstream::setMasterSlave
void setMasterSlave(bool master)
Set if this processor is slave or master.
Definition: masterOstream.hpp:68
pFlow::processors::initProcessorsCelled_
static bool initProcessorsCelled_
Is the static member initProcessors is called.
Definition: processors.hpp:57
pFlow::processors::abort
static void abort(int error)
Abort MPI run or regular run.
Definition: processors.cpp:147
pFlow::processors::argv_
static char ** argv_
Definition: processors.hpp:71
error.hpp
pFlow::processors::isInitialized
static bool isInitialized()
Is MPI initialized?
Definition: processors.cpp:123