OOFEM 3.0
Loading...
Searching...
No Matches
processcomm.C
Go to the documentation of this file.
1/*
2 *
3 * ##### ##### ###### ###### ### ###
4 * ## ## ## ## ## ## ## ### ##
5 * ## ## ## ## #### #### ## # ##
6 * ## ## ## ## ## ## ## ##
7 * ## ## ## ## ## ## ## ##
8 * ##### ##### ## ###### ## ##
9 *
10 *
11 * OOFEM : Object Oriented Finite Element Code
12 *
13 * Copyright (C) 1993 - 2025 Borek Patzak
14 *
15 *
16 *
17 * Czech Technical University, Faculty of Civil Engineering,
18 * Department of Structural Mechanics, 166 29 Prague, Czech Republic
19 *
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License as published by the Free Software Foundation; either
23 * version 2.1 of the License, or (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Lesser General Public License for more details.
29 *
30 * You should have received a copy of the GNU Lesser General Public
31 * License along with this library; if not, write to the Free Software
32 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33 */
34
35#include "processcomm.h"
36#include "intarray.h"
37#include "combuff.h"
38#include "dyncombuff.h"
39
40#ifdef __USE_MPI
41 #include <mpi.h>
42#endif
43
44namespace oofem {
45ProcessCommunicatorBuff :: ProcessCommunicatorBuff(CommBuffType t)
46{
47 if ( t == CBT_static ) {
48 send_buff = std::make_unique<StaticCommunicationBuffer>(MPI_COMM_WORLD);
49 recv_buff = std::make_unique<StaticCommunicationBuffer>(MPI_COMM_WORLD);
50 } else {
51 send_buff = std::make_unique<DynamicCommunicationBuffer>(MPI_COMM_WORLD);
52 recv_buff = std::make_unique<DynamicCommunicationBuffer>(MPI_COMM_WORLD);
53 }
54}
55
56
57ProcessCommunicator :: ProcessCommunicator(ProcessCommunicatorBuff *b, int rank, CommunicatorMode m) :
58 rank(rank),
59 pcBuffer(b),
60 toSend(), toReceive(),
61 mode(m)
62{
63}
64
65
66int
67ProcessCommunicator :: initSend(int tag)
68{
69 int result = 1;
70 if ( !toSend.isEmpty() || ( this->mode == CommMode_Dynamic ) ) {
71 // fprintf (stderr, "\nNlDEIDynamicDomainComunicator :: initExchange: sending to %d",rank);
72 result = giveProcessCommunicatorBuff()->initSend(this->rank, tag);
73 } else {
74 giveProcessCommunicatorBuff()->initSendBuff();
75 }
76
77 return result;
78}
79
80
81int
82ProcessCommunicator :: initReceive(int tag)
83{
84 int result = 1;
85 if ( !toReceive.isEmpty() || ( this->mode == CommMode_Dynamic ) ) {
86 // fprintf (stderr, "\nNlDEIDynamicDomainComunicator :: initExchange: recv from %d",rank);
87 result &= giveProcessCommunicatorBuff()->initReceive(this->rank, tag);
88 } else {
89 giveProcessCommunicatorBuff()->initRecvBuff();
90 }
91
92 return result;
93}
94
95
96int
97ProcessCommunicator :: initExchange(int tag)
98{
99 int result = 1;
100 result &= initSend(tag);
101 result &= initReceive(tag);
102
103 return result;
104}
105
106int
107ProcessCommunicator :: finishExchange()
108{
109 return waitCompletion();
110}
111
112void
113ProcessCommunicator :: clearBuffers()
114{
116}
117
118int
119ProcessCommunicator :: sendCompleted()
120{
121 if ( !toSend.isEmpty() || ( this->mode == CommMode_Dynamic ) ) {
122 return giveProcessCommunicatorBuff()->sendCompleted();
123 } else {
124 return 1;
125 }
126}
127
128int
129ProcessCommunicator :: receiveCompleted()
130{
131 if ( !toReceive.isEmpty() || ( this->mode == CommMode_Dynamic ) ) {
132 return giveProcessCommunicatorBuff()->receiveCompleted();
133 } else {
134 return 1;
135 }
136}
137
138int
139ProcessCommunicator :: testCompletion()
140{
141 return ( sendCompleted() && receiveCompleted() );
142}
143
144int
145ProcessCommunicator :: waitCompletion()
146{
147 while ( !testCompletion() ) {
148 ;
149 }
150
151 return 1;
152}
153} // end namespace oofem
std::unique_ptr< CommunicationBuffer > recv_buff
Receive buffer.
Definition processcomm.h:72
std::unique_ptr< CommunicationBuffer > send_buff
Send buffer.
Definition processcomm.h:70
IntArray toReceive
Nodes to receive.
ProcessCommunicatorBuff * giveProcessCommunicatorBuff()
Returns communication buffer.
IntArray toSend
Nodes to send.
ProcessCommunicatorBuff * pcBuffer
Communicator buffers representation.
CommunicatorMode mode
Mode.
int rank
Associated partition (problem) number (rank).
@ CBT_static

This page is part of the OOFEM-3.0 documentation. Copyright Copyright (C) 1994-2025 Borek Patzak Bořek Patzák
Project e-mail: oofem@fsv.cvut.cz
Generated at for OOFEM by doxygen 1.15.0 written by Dimitri van Heesch, © 1997-2011