OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
communicator.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 - 2013 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 "communicator.h"
36 #include "intarray.h"
37 
38 #include <cstdarg>
39 
40 #ifdef __USE_MPI
41  #include <mpi.h>
42 #endif
43 
44 namespace oofem {
46 {
47  this->size = s;
48 
49  if ( size ) {
51  for ( int i = 0; i < size; i++ ) {
53  }
54  } else {
55  processCommBuffs = NULL;
56  }
57 }
58 
60 {
61  for ( int i = 0; i < size; i++ ) {
62  if ( processCommBuffs [ i ] ) {
63  delete(processCommBuffs [ i ]);
64  }
65  }
66 
67  if ( processCommBuffs ) {
68  delete[] processCommBuffs;
69  }
70 }
71 
73 {
74  this->engngModel = emodel;
75  this->rank = rank;
76  this->size = size;
77  this->mode = m;
78 
79  if ( size ) {
80  processComms = new ProcessCommunicator * [ size ];
81  for ( int i = 0; i < size; i++ ) {
82  processComms [ i ] =
83  new ProcessCommunicator(b->giveProcessCommunicatorBuff ( i ), i, mode);
84  }
85  } else {
86  processComms = NULL;
87  }
88 }
89 
91 {
92  int i = size;
93 
94  if ( size ) {
95  while ( i-- ) {
96  delete(processComms [ i ]);
97  }
98 
99  delete[] processComms;
100  }
101 }
102 
103 int
105 {
106  int result = 1;
107  for ( int i = 0; i < size; i++ ) {
108  result &= this->giveProcessCommunicator(i)->initExchange(tag);
109  }
110 
111  return result;
112 }
113 
114 int
116 {
117  int result = 1;
118  for ( int i = 0; i < size; i++ ) {
119  result &= this->giveProcessCommunicator(i)->finishExchange();
120  }
121 
122  return result;
123 }
124 
125 
126 
127 int
129 {
130  int result = 1;
131  for ( int i = 0; i < size; i++ ) {
132  result &= this->giveProcessCommunicator(i)->initSend(tag);
133  }
134 
135  return result;
136 }
137 
138 int
140 {
141  int result = 1;
142  for ( int i = 0; i < size; i++ ) {
143  result &= this->giveProcessCommunicator(i)->initReceive(tag);
144  }
145 
146  return result;
147 }
148 
149 void
151 {
152  for ( int i = 0; i < size; i++ ) {
153  this->giveProcessCommunicator(i)->clearBuffers();
154  }
155 }
156 
157 std :: string
158 Communicator :: errorInfo(const char *func) const
159 {
160  return std::string("Communicator::") + func + ", Rank: " + std::to_string(rank);
161 }
162 } // end namespace oofem
Communicator(EngngModel *emodel, CommunicatorBuff *buff, int rank, int size, CommunicatorMode mode=CommMode_Static)
Constructor.
Definition: communicator.C:72
ProcessCommunicatorBuff * giveProcessCommunicatorBuff(int i)
Returns i-th process communicator buff.
Definition: communicator.h:78
int initExchange(int tag)
Initializes data exchange with all problems.
Definition: communicator.C:104
int size
Number of processes.
Definition: communicator.h:64
std::string errorInfo(const char *func) const
Returns string for prepending output (used by error reporting macros).
Definition: communicator.C:158
CommBuffType
Definition: commbufftype.h:40
The ProcessCommunicator and corresponding buffers (represented by this class) are separated in order ...
Definition: processcomm.h:64
int finishExchange()
Finishes the exchange.
Definition: communicator.C:115
CommunicatorMode
The communicator mode determines the communication.
void clearBuffers()
Clears all buffer content.
Definition: communicator.C:150
Class representing process communicator for engineering model.
Definition: processcomm.h:176
virtual ~Communicator()
Destructor.
Definition: communicator.C:90
ProcessCommunicatorBuff ** processCommBuffs
Array of process communicators.
Definition: communicator.h:66
int initSend(int tag)
Initializes data send exchange with all problems.
Definition: communicator.C:128
The Communicator and corresponding buffers (represented by this class) are separated in order to allo...
Definition: communicator.h:60
Abstract base class representing the "problem" under consideration.
Definition: engngm.h:181
the oofem namespace is to define a context or scope in which all oofem names are defined.
int initReceive(int tag)
Initializes data receive exchange with all problems.
Definition: communicator.C:139
CommunicatorBuff(int s, CommBuffType t=CBT_static)
Definition: communicator.C:45

This page is part of the OOFEM documentation. Copyright (c) 2011 Borek Patzak
Project e-mail: info@oofem.org
Generated at Tue Jan 2 2018 20:07:27 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011