ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
para_world.h
Go to the documentation of this file.
1#ifndef PARA_WORLD_H
2#define PARA_WORLD_H
3
4#include <memory>
5#include <string>
6
7#ifdef __MPI
8#include "mpi.h"
9#endif
10
11namespace Parallel
12{
13
28{
29public:
30 virtual ~ParaWorld() = default;
31
33 const std::string& tag() const
34 {
35 return tag_;
36 }
37
39 int rank() const
40 {
41 return rank_;
42 }
43
45 int size() const
46 {
47 return size_;
48 }
49
56 bool valid() const;
57
58#ifdef __MPI
60 MPI_Comm comm() const
61 {
62 return comm_;
63 }
64#endif
65
72 static ParaWorld serial(const std::string& tag)
73 {
74 return ParaWorld(tag);
75 }
76
82 static std::unique_ptr<ParaWorld> make_serial(const std::string& tag)
83 {
84 return std::unique_ptr<ParaWorld>(new ParaWorld(tag));
85 }
86
87#ifdef __MPI
94 static ParaWorld make_mpi(const std::string& tag, const MPI_Comm& comm)
95 {
96 return ParaWorld(tag, comm);
97 }
98
99 static std::unique_ptr<ParaWorld> make_mpi_ptr(const std::string& tag, const MPI_Comm& comm)
100 {
101 return std::unique_ptr<ParaWorld>(new ParaWorld(tag, comm));
102 }
103#endif
104
105protected:
116 explicit ParaWorld(const std::string& tag);
117
118#ifdef __MPI
126 ParaWorld(const std::string& tag, const MPI_Comm& comm);
127#endif
128
129private:
130 std::string tag_;
131 int rank_;
132 int size_;
133#ifdef __MPI
134 MPI_Comm comm_;
135#endif
136};
137
138} // namespace Parallel
139
140#endif // PARA_WORLD_H
MPI_Comm comm_
wrapped communicator (never owned/freed here)
Definition para_world.h:134
std::string tag_
domain tag
Definition para_world.h:130
virtual ~ParaWorld()=default
MPI_Comm comm() const
Underlying MPI communicator (MPI builds only).
Definition para_world.h:60
int size_
number of processes in domain
Definition para_world.h:132
static std::unique_ptr< ParaWorld > make_mpi_ptr(const std::string &tag, const MPI_Comm &comm)
Definition para_world.h:99
int rank() const
Rank of this process inside the domain (0 in serial builds).
Definition para_world.h:39
int rank_
rank inside domain
Definition para_world.h:131
const std::string & tag() const
Domain tag string.
Definition para_world.h:33
static std::unique_ptr< ParaWorld > make_serial(const std::string &tag)
Build a serial domain as a heap-allocated unique_ptr.
Definition para_world.h:82
ParaWorld(const std::string &tag)
Construct a serial (single-process) domain.
Definition para_world.cpp:6
bool valid() const
True if this process belongs to the domain.
Definition para_world.cpp:34
static ParaWorld make_mpi(const std::string &tag, const MPI_Comm &comm)
Build a domain wrapping an MPI communicator.
Definition para_world.h:94
int size() const
Number of processes in the domain (1 in serial builds).
Definition para_world.h:45
static ParaWorld serial(const std::string &tag)
Build a serial (size=1, rank=0) domain for the given tag.
Definition para_world.h:72
Definition para_band_output.cpp:11