PeriDEM 0.2.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 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 MpiStatusgetMpiStatus ()
 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

◆ getMpiStatus()

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

Returns pointer to MpiStatus struct.

Returns
pointer Pointer to MpiStatus object

Definition at line 101 of file parallelUtil.cpp.

101 {
102 //assert(mpiInitialized && "mpiInitialized is false indicating MPI_Init() or util::parallel::initMpi() has not been called.\n");
103 if (mpistatus_p == nullptr)
105
106 return mpistatus_p;
107}
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(), and 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 116 of file parallelUtil.cpp.

116 {
117 if (numThreads == 0)
118 numThreads = std::thread::hardware_concurrency();
119 return numThreads;
120}

Referenced by loading::ParticleFLoading::apply(), loading::ParticleULoading::apply(), model::DEMModel::applyInitialCondition(), model::DEMModel::computeContactForces(), model::DEMModel::computeExternalForces(), model::DEMModel::computeForces(), peridynamics::Model::computeForces(), material::computeHydrostaticStrain(), model::DEMModel::computePeridynamicForces(), material::computeStateMx(), material::computeStateThetax(), fe::Mesh::computeVol(), geometry::Fracture::Fracture(), fe::getCurrentQuadPoints(), fe::getStrainStress(), model::DEMModel::integrateCD(), model::DEMModel::integrateVerlet(), 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(), model::DEMModel::updateContactNeighborlist(), and model::DEMModel::updatePeridynamicNeighborlist().

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(), 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 55 of file parallelUtil.cpp.

55 {
56 if (mpistatus_p != nullptr)
57 return;
58
60}
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 109 of file parallelUtil.cpp.

109 {
110 if (numThreads > 0) {
111 std::cout << "Number of threads numThreads is already initialized.\n";
112 } else
113 numThreads = nThreads;
114}

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 62 of file parallelUtil.cpp.

62 {
63
64 // for now, we do not call assert and rather create MpiStatus if it is not instantiated
65 /*
66 //assert((mpistatus_p != nullptr) && "mpistatus_p "
67 // "(pointer of struct type util::parallel::MpiStatus) is not initialized. "
68 // "Call util::parallel::initMpiStatus() possibly right after MPI_Init().");
69 */
70 //assert(mpiInitialized && "mpiInitialized is false indicating MPI_Init() or util::parallel::initMpi() has not been called.\n");
71 if (mpistatus_p == nullptr)
73
75}
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().

Here is the call graph for this function:

◆ mpiComm()

MPI_Comm util::parallel::mpiComm ( )

Get MPI comm.

Returns
comm MPI comm

Definition at line 93 of file parallelUtil.cpp.

93 {
94 //assert(mpiInitialized && "mpiInitialized is false indicating MPI_Init() or util::parallel::initMpi() has not been called.\n");
95 if (mpistatus_p == nullptr)
97
98 return mpistatus_p->d_comm;
99}
MPI_Comm d_comm
MPI comm.

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

Here is the call graph for this function:

◆ mpiRank()

int util::parallel::mpiRank ( )

get rank (id) of this processor

Returns
int Rank of MPI process

Definition at line 85 of file parallelUtil.cpp.

85 {
86 //assert(mpiInitialized && "mpiInitialized is false indicating MPI_Init() or util::parallel::initMpi() has not been called.\n");
87 if (mpistatus_p == nullptr)
89
90 return mpistatus_p->d_mpiRank;
91}
int d_mpiRank
Rank (id) of this processor.

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

Referenced by util::io::Logger::log(), main(), main(), util::io::print(), util::io::print(), util::io::print(), util::io::printBox(), and util::io::printBox().

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 77 of file parallelUtil.cpp.

77 {
78 //assert(mpiInitialized && "mpiInitialized is false indicating MPI_Init() or util::parallel::initMpi() has not been called.\n");
79 if (mpistatus_p == nullptr)
81
82 return mpistatus_p->d_mpiSize;
83}
int d_mpiSize
Size (number) of processors.

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

Referenced by main(), and main().

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