b2api
B2000++ API Reference Manual, VERSION 4.6
 
Loading...
Searching...
No Matches
b2comm_Serial.H
1//------------------------------------------------------------------------
2// b2comm_Serial.H
3//
4// written by Harald Klimach <harald.klimach@dlr.de>
5// Neda Ebrahimi Pour <neda.ebrahimipour@dlr.de>
6//
7// (c) 2021 Deutsches Zentrum für Luft- und Raumfahrt (DLR) e.V.
8// Linder Höhe, 51147 Köln
9//
10// All Rights Reserved. Proprietary source code. The contents of
11// this file may not be disclosed to third parties, copied or
12// duplicated in any form, in whole or in part, without the prior
13// written permission of DLR.
14//
15//------------------------------------------------------------------------
16
17#ifndef B2COMM_SERIAL_H_
18#define B2COMM_SERIAL_H_
19
20//------------------------------------------------------------------------
21//
22// \file
23// Serial communicator encapsulation. Provides dummy communicator when
24// no distributed parallel infrastructue is available.
25//
26//------------------------------------------------------------------------
27
28#include <map>
29
30#include "b2ppconfig.h"
31#include "utils/b2comm.H"
32
33#define B2_NOCOMM -987654
34
35namespace b2000 {
36
37// Dummy communication implementation, if there is no distributed memory
38// parallelization available.
39//
40// This class realizes a dummy "communication" if there is only one process
41// available.
42class B2serial : public Communicator {
43public:
44 static constexpr bool supported = true;
45
46 // A main constructor to initialize the communicator as the one of the
47 // main program.
48 B2serial(int argc, char* argv[]) : rank_(0), size_(1) {
49 // Nothing to do for serial programs.
50 }
51
52 explicit B2serial() = default;
53
54 ~B2serial() override{};
55
56 // Rank of the running process
57 int rank() const override { return rank_; }
58
59 // Number of processes in the communicator
60 int NumRanks() const override { return size_; }
61
62 // Is running process root?
63 bool IsRoot() const override { return (0 == rank_); }
64
65 // Additional command line options for the communication
66 void CmdOpts(cmdline::CmdLine& cmdline) override {
67 // No additional command line options necessary for the MPI
68 // communication.
69 }
70
71 // Get a communicator handle for Fortran, needed by MUMPS.
72 // We return B2_NOCOMM here, which is understood by MUMPS as a special
73 // value to not do communication.
74 int GetFcomm() const override { return B2_NOCOMM; }
75
76 // Abort the parallel execution
77 void Abort(int errorcode) override {
78 // Nothing to do in serial
79 }
80
81 // Wait on other processes
82 void Barrier() override {
83 // Nothing to do in serial
84 }
85
86 // Receive a message from rank source with tag within the communicator.
87 void Recv(char buffer[], uint64_t length, int source, int tag) override {
88 buffer = static_cast<char*>(buffers_[tag].ptr);
89 }
90
91 // Send a message to rank target with tag within the communicator.
92 void Send(char buffer[], uint64_t length, int target, int tag) override {
93 buffers_[tag].ptr = static_cast<void*>(buffer);
94 buffers_[tag].num_bytes = length * sizeof buffer[0];
95 }
96
97 // Broadcast a buffer from root to all in the communicator
98 // Nothing to do in serial with a single root process.
99 void Bcast(uint64_t buffer[], uint64_t length, int root = 0) override {}
100 void Bcast(int buffer[], uint64_t length, int root = 0) override {}
101 void Bcast(double buffer[], uint64_t length, int root = 0) override {}
102
103 // Probe an incoming message for its size in bytes (before calling
104 // the corresponding receive).
105 uint64_t ProbeByteCount(int source, int tag) override {
106 return static_cast<uint64_t>(buffers_[tag].num_bytes);
107 }
108
109private:
110 struct buffer_t {
111 void* ptr;
112 size_t num_bytes;
113 };
114
115 std::map<int, buffer_t> buffers_;
116
117 // Identification of the running process
118 int rank_ = 0;
119
120 // Size of the Communicator
121 int size_ = 1;
122
123}; // class B2serial
124
125} // namespace b2000
126
127#endif // B2COMM_SERIAL_H_
Contains the base classes for implementing Finite Elements.
Definition b2boundary_condition.H:32