Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
ModelMPIbase.cpp
Go to the documentation of this file.
1/* This file is part of MoDELib, distributed under GNU GPL v2. */
2#include <MPI/ModelMPIbase.h>
3#include <iostream>
4#include <mpi.h>
5#include <assert.h>
6#include <TerminalColors.h>
7
8namespace model
9{
10
12 {
15 }
16
20
22 {
24 MPI_Finalize();
25 }
26
27 auto ModelMPIbase::initMPI(int argc, char *argv[]) -> void
28 {
29 MPI_Initialized(&_mpiInitialized);
30 if (!_mpiInitialized)
31 {
32 MPI_Init(&argc, &argv);
33
34 // Verify
35 MPI_Initialized(&_mpiInitialized);
36 assert(_mpiInitialized && "MPI not initialized.");
37
38 MPI_Comm_rank(MPI_COMM_WORLD, &_mpiRank);
39 MPI_Comm_size(MPI_COMM_WORLD, &_mpiProcs);
40
41 int tempLen;
42 char tempName[MPI_MAX_PROCESSOR_NAME];
43 MPI_Get_processor_name(tempName, &tempLen);
44 _processorName = tempName;
45
46 std::cout << greenBoldColor << "MPI process " << _mpiRank << " of "
47 << _mpiProcs
48 /* */
49 << " (on node " << _processorName << "), mpiInitialized=" << _mpiInitialized << defaultColor
50 << std::endl;
51
52 MPI_Barrier(MPI_COMM_WORLD);
53 }
54 }
55
56 auto ModelMPIbase::mpiRank() -> const int &
57 {
58 return _mpiRank;
59 }
60
61 auto ModelMPIbase::mpiProcs() -> const int &
62 {
63 return _mpiProcs;
64 }
65
66 auto ModelMPIbase::mpiInitialized() -> const int &
67 {
68 return _mpiInitialized;
69 }
70
71 auto ModelMPIbase::processorName() -> const std::string &
72 {
73 return _processorName;
74 }
75
76 // static data
77 int ModelMPIbase::_mpiInitialized = 0;
78 int ModelMPIbase::_mpiRank = 0;
79 int ModelMPIbase::_mpiProcs = 1;
80 std::string ModelMPIbase::_processorName = "NO NAME ASSIGNED YET";
81
82} // namespace model
static void initMPI(int argc, char *argv[])
static const int & mpiInitialized()
static const std::string & processorName()
static const int & mpiRank()
static const int & mpiProcs()
static std::string greenBoldColor
static std::string defaultColor
void argv
void b int argc