PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
util::parallel Namespace Reference

Implements some key functions and classes regularly used in the code when running with MPI. More...

Data Structures

struct  MpiStatus
 Struct that stores MPI-related information. More...
 

Functions

void initMpi (int argc=0, char *argv[]=nullptr)
 Initializes MPI and also creates MpiStatus struct.
 
void finalizeMpi ()
 Call MPI_Finalize if this process initialized MPI.
 
void initMpiStatus ()
 Initializes MpiStatus struct.
 
bool isMpiEnabled ()
 Function to check if MPI is enabled.
 
int mpiSize ()
 Get size (number) of processors.
 
int mpiRank ()
 get rank (id) of this processor
 
MPI_Comm mpiComm ()
 Get MPI comm.
 
const MpiStatus * getMpiStatus ()
 Returns pointer to MpiStatus struct.
 
void initNThreads (unsigned int nThreads=std::thread::hardware_concurrency())
 Initializes MpiStatus struct.
 
unsigned int getNThreads ()
 Get number of threads to be used by taskflow.
 

Detailed Description

Implements some key functions and classes regularly used in the code when running with MPI.

Function Documentation

◆ finalizeMpi()

void util::parallel::finalizeMpi ( )

Call MPI_Finalize if this process initialized MPI.

Definition at line 33 of file parallelUtil.cpp.

33 {
34 int initialized = 0;
35 MPI_Initialized(&initialized);
36 if (!initialized)
37 return;
38 int finalized = 0;
39 MPI_Finalized(&finalized);
40 if (!finalized)
41 MPI_Finalize();
42}

Referenced by main().

Here is the caller graph for this function:

◆ getMpiStatus()

const util::parallel::MpiStatus * util::parallel::getMpiStatus ( )

Returns pointer to MpiStatus struct.

Returns
pointer Pointer to MpiStatus object

Definition at line 112 of file parallelUtil.cpp.

112 {
113 //assert(mpiInitialized && "mpiInitialized is false indicating MPI_Init() or util::parallel::initMpi() has not been called.\n");
114 if (mpistatus_p == nullptr)
116
117 return mpistatus_p;
118}
util::parallel::MpiStatus * mpistatus_p
void initMpi(int argc=0, char *argv[]=nullptr)
Initializes MPI and also creates MpiStatus struct.

References initMpi().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getNThreads()

unsigned int util::parallel::getNThreads ( )

Get number of threads to be used by taskflow.

Returns
nThreads Number of threads

Definition at line 127 of file parallelUtil.cpp.

127 {
128 if (numThreads == 0)
129 numThreads = std::thread::hardware_concurrency();
130 return numThreads;
131}

Referenced by contact::AnalyticalPlaneWallContact::apply(), loading::applyIC(), PeriDEMModel::computeExternalForces(), PeriDEMModel::computeForces(), contact::Contact::computeForces(), pd::computeForces(), material::computeHydrostaticStrain(), material::computeStateMx(), material::computeStateThetax(), mesh::Mesh::computeVol(), geometry::Fracture::Fracture(), mesh::getCurrentQuadPoints(), mesh::getStrainStress(), main(), anonymous_namespace{testNSearchLib.cpp}::neighSearchBrute(), anonymous_namespace{testNSearchLib.cpp}::neighSearchBruteExcludeInclude(), anonymous_namespace{testNSearchLib.cpp}::neighSearchTree(), anonymous_namespace{testNSearchLib.cpp}::neighSearchTreeClosestPointSizet(), anonymous_namespace{testNSearchLib.cpp}::neighSearchTreeSizet(), anonymous_namespace{testNSearchLib.cpp}::neighSearchTreeSizetExcludeInclude(), test::testTaskflow(), material::updateBondFractureData(), time_int::updateCentralDifference(), contact::Contact::updateNeighborlist(), nsearch::updatePeridynamicNeighborlist(), time_int::updateVerletHalfKickAndDrift(), and time_int::updateVerletSecondKick().

Here is the caller graph for this function:

◆ initMpi()

void util::parallel::initMpi ( int  argc = 0,
char *  argv[] = nullptr 
)

Initializes MPI and also creates MpiStatus struct.

Parameters
argcCommand line argument number
argvCommand line argument values

Definition at line 25 of file parallelUtil.cpp.

25 {
26
27 MPI_Initialized(&mpiInitialized);
28 if (!mpiInitialized)
29 MPI_Init(&argc, &argv);
31}
void initMpiStatus()
Initializes MpiStatus struct.

References initMpiStatus(), and anonymous_namespace{parallelUtil.cpp}::mpiInitialized.

Referenced by getMpiStatus(), isMpiEnabled(), main(), mpiComm(), mpiRank(), and mpiSize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initMpiStatus()

void util::parallel::initMpiStatus ( )

Initializes MpiStatus struct.

Definition at line 66 of file parallelUtil.cpp.

66 {
67 if (mpistatus_p != nullptr)
68 return;
69
71}
Struct that stores MPI-related information.

Referenced by initMpi().

Here is the caller graph for this function:

◆ initNThreads()

void util::parallel::initNThreads ( unsigned int  nThreads = std::thread::hardware_concurrency())

Initializes MpiStatus struct.

Parameters
nThreadsNumber of threads to be used by Taskflow in asynchronous parallelism

Definition at line 120 of file parallelUtil.cpp.

120 {
121 if (numThreads > 0) {
122 std::cout << "Number of threads numThreads is already initialized.\n";
123 } else
124 numThreads = nThreads;
125}

Referenced by main().

Here is the caller graph for this function:

◆ isMpiEnabled()

bool util::parallel::isMpiEnabled ( )

Function to check if MPI is enabled.

Returns
bool Bool

Definition at line 73 of file parallelUtil.cpp.

73 {
74
75 // MpiStatus is created if it is not instantiated rather than asserting.
76 /*
77 //assert((mpistatus_p != nullptr) && "mpistatus_p "
78 // "(pointer of struct type util::parallel::MpiStatus) is not initialized. "
79 // "Call util::parallel::initMpiStatus() possibly right after MPI_Init().");
80 */
81 //assert(mpiInitialized && "mpiInitialized is false indicating MPI_Init() or util::parallel::initMpi() has not been called.\n");
82 if (mpistatus_p == nullptr)
84
86}
bool d_mpiEnabled
Specifies if MPI is enabled (yes if code executed with more than one processor)

References util::parallel::MpiStatus::d_mpiEnabled, and initMpi().

Referenced by particle::assignMpiOwners(), contact::Contact::computeForces(), particle::exchangeGhostKinematics(), particle::isLocallyOwned(), main(), pd::setupDofPartition(), and contact::Contact::updateNeighborlist().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mpiComm()

MPI_Comm util::parallel::mpiComm ( )

Get MPI comm.

Returns
comm MPI comm

Definition at line 104 of file parallelUtil.cpp.

104 {
105 //assert(mpiInitialized && "mpiInitialized is false indicating MPI_Init() or util::parallel::initMpi() has not been called.\n");
106 if (mpistatus_p == nullptr)
108
109 return mpistatus_p->d_comm;
110}
MPI_Comm d_comm
MPI comm.

References util::parallel::MpiStatus::d_comm, and initMpi().

Referenced by anonymous_namespace{main.cpp}::ContactWitness::assertOk(), anonymous_namespace{pdMpi.cpp}::buildGhostPlan(), anonymous_namespace{main.cpp}::ContactWitness::checkStop(), MpiMetricTsProbe::checkStop(), postprocess::Postprocess::compressive(), anonymous_namespace{main.cpp}::dumpFinalNodal(), MpiMetricTsProbe::dumpNodalUV(), anonymous_namespace{particleMpi.cpp}::exchangeCachedKinematics(), anonymous_namespace{pdMpi.cpp}::exchangeDoubles(), particle::exchangeGhostKinematics(), pd::exchangeGhostTheta(), anonymous_namespace{pdMpi.cpp}::exchangePoints(), main(), anonymous_namespace{particleMpi.cpp}::rebuildGhostPlan(), anonymous_namespace{main.cpp}::GrainContactProbe::sampleMetric(), pd::setupDofPartition(), anonymous_namespace{pdMpi.cpp}::syncAllOwnedPoints(), and rw::writeOutput().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mpiRank()

int util::parallel::mpiRank ( )

get rank (id) of this processor

Returns
int Rank of MPI process

Definition at line 96 of file parallelUtil.cpp.

96 {
97 //assert(mpiInitialized && "mpiInitialized is false indicating MPI_Init() or util::parallel::initMpi() has not been called.\n");
98 if (mpistatus_p == nullptr)
100
101 return mpistatus_p->d_mpiRank;
102}
int d_mpiRank
Rank (id) of this processor.

References util::parallel::MpiStatus::d_mpiRank, and initMpi().

Referenced by rw::writer::VtkParticleWriter::appendMeshParallelPiece(), contact::Damping::apply(), anonymous_namespace{main.cpp}::ContactWitness::assertOk(), particle::assignMpiOwners(), anonymous_namespace{pdMpi.cpp}::buildGhostPlan(), MpiMetricTsProbe::checkStop(), postprocess::Postprocess::compressive(), PeriDEMModel::computeExternalForces(), anonymous_namespace{main.cpp}::dumpFinalNodal(), MpiMetricTsProbe::dumpNodalUV(), pd::exchangeGhostTheta(), PeriDEMModel::init(), particle::isLocallyOwned(), util::io::Logger::log(), main(), MpiMetricTsProbe::MpiMetricTsProbe(), anonymous_namespace{main.cpp}::GrainContactProbe::ownsNode(), anonymous_namespace{main.cpp}::ownsNode(), MpiMetricTsProbe::ownsNode(), util::io::print(), util::io::print(), util::io::print(), util::io::printBox(), util::io::printBox(), anonymous_namespace{particleMpi.cpp}::rebuildGhostPlan(), anonymous_namespace{main.cpp}::GrainContactProbe::sampleMetric(), pd::setupDofPartition(), anonymous_namespace{pdMpi.cpp}::syncAllOwnedPoints(), and rw::writeOutput().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mpiSize()

int util::parallel::mpiSize ( )

Get size (number) of processors.

Returns
int Size of MPI processes

Definition at line 88 of file parallelUtil.cpp.

88 {
89 //assert(mpiInitialized && "mpiInitialized is false indicating MPI_Init() or util::parallel::initMpi() has not been called.\n");
90 if (mpistatus_p == nullptr)
92
93 return mpistatus_p->d_mpiSize;
94}
int d_mpiSize
Size (number) of processors.

References util::parallel::MpiStatus::d_mpiSize, and initMpi().

Referenced by rw::writer::VtkParticleWriter::appendMeshParallelPiece(), anonymous_namespace{main.cpp}::ContactWitness::assertOk(), particle::assignMpiOwners(), anonymous_namespace{pdMpi.cpp}::buildGhostPlan(), anonymous_namespace{main.cpp}::ContactWitness::checkStop(), MpiMetricTsProbe::checkStop(), postprocess::Postprocess::compressive(), anonymous_namespace{main.cpp}::dumpFinalNodal(), MpiMetricTsProbe::dumpNodalUV(), anonymous_namespace{particleMpi.cpp}::exchangeCachedKinematics(), anonymous_namespace{pdMpi.cpp}::exchangeDoubles(), pd::exchangeGhostDisplacement(), anonymous_namespace{pdMpi.cpp}::exchangePoints(), main(), anonymous_namespace{particleMpi.cpp}::rebuildGhostPlan(), anonymous_namespace{main.cpp}::GrainContactProbe::sampleMetric(), pd::setupDofPartition(), contact::Contact::updateNeighborlist(), and rw::writeOutput().

Here is the call graph for this function:
Here is the caller graph for this function: