OOFEM 3.0
Loading...
Searching...
No Matches
parallelcontext.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 "parallelcontext.h"
36#include "engngm.h"
37#include "mathfem.h"
39
40namespace oofem {
41//#define ParallelContext_debug_print
42
43ParallelContext :: ParallelContext(EngngModel *e)
44#ifdef __MPI_PARALLEL_MODE
45 : n2g(), n2l()
46#endif
47{
48 this->emodel = e;
49}
50
51ParallelContext :: ~ParallelContext()
52{ }
53
54void
55ParallelContext :: init(int newDi)
56{
57 di = newDi;
59#ifdef __MPI_PARALLEL_MODE
60 if ( emodel->isParallel() ) {
64
65 #ifdef __VERBOSE_PARALLEL
66 fprintf( stderr, "[%d] ParallelContext :: init - leq:%d, neq:%d, geq:%d\n", emodel->giveRank(), giveNumberOfLocalEqs(), giveNumberOfNaturalEqs(), giveNumberOfGlobalEqs() );
67 #endif
68 }
69
70#endif
71}
72
73
74int
75ParallelContext :: giveNumberOfLocalEqs()
76{
77#ifdef __MPI_PARALLEL_MODE
78 if ( emodel->isParallel() ) {
79 return n2g.giveNumberOfLocalEqs();
80 } else {
81#endif
82 return emodel->giveNumberOfDomainEquations( di, EModelDefaultEquationNumbering() );
83
84#ifdef __MPI_PARALLEL_MODE
85}
86#endif
87}
88
89
90int
91ParallelContext :: giveNumberOfGlobalEqs()
92{
93#ifdef __MPI_PARALLEL_MODE
94 if ( emodel->isParallel() ) {
95 return n2g.giveNumberOfGlobalEqs();
96 } else {
97#endif
98 return emodel->giveNumberOfDomainEquations( di, EModelDefaultEquationNumbering() );
99
100#ifdef __MPI_PARALLEL_MODE
101}
102#endif
103}
104
105int
106ParallelContext :: giveNumberOfNaturalEqs()
107{
108 return emodel->giveNumberOfDomainEquations( di, EModelDefaultEquationNumbering() );
109}
110
111
112bool
113ParallelContext :: isLocal(DofManager *dman)
114{
115#ifdef __PARALLE_MODE
116 if ( emodel->isParallel() ) {
117 return this->giveN2GMap()->isLocal(dman); // Either map is fine.
118 }
119#else
120 return true;
121
122#endif
123}
124
125
126double
127ParallelContext :: localNorm(const FloatArray &src)
128{
129#ifdef __MPI_PARALLEL_MODE
130 if ( emodel->isParallel() ) {
131 double norm2 = 0.0, norm2_tot;
132 int size = src.giveSize();
134 for ( int i = 0; i < size; i++ ) {
135 if ( n2l->giveNewEq(i + 1) ) {
136 norm2 += src(i) * src(i);
137 }
138 }
139 MPI_Allreduce( & norm2, & norm2_tot, 1, MPI_DOUBLE, MPI_SUM, this->emodel->giveParallelComm() );
140 return sqrt(norm2_tot);
141 }
142#endif
143 return src.computeNorm();
144}
145
146
147double
148ParallelContext :: localDotProduct(const FloatArray &a, const FloatArray &b)
149{
150#ifdef __MPI_PARALLEL_MODE
151 if ( emodel->isParallel() ) {
152 double val = 0.0, val_tot = 0.0;
153 int size = a.giveSize();
155 for ( int i = 0; i < size; i++ ) {
156 if ( n2l->giveNewEq(i + 1) ) {
157 val += a(i) * b(i);
158 }
159 }
160 MPI_Allreduce( & val, & val_tot, 1, MPI_DOUBLE, MPI_SUM, this->emodel->giveParallelComm() );
161 return val_tot;
162 }
163#endif
164 return a.dotProduct(b);
165}
166
167
168double
169ParallelContext :: accumulate(double local)
170{
171#ifdef __MPI_PARALLEL_MODE
172 if ( emodel->isParallel() ) {
173 double global;
174 MPI_Allreduce( & local, & global, 1, MPI_DOUBLE, MPI_SUM, this->emodel->giveParallelComm() );
175 return global;
176 }
177#endif
178 return local;
179}
180
181
182
183void
184ParallelContext :: accumulate(const FloatArray &local, FloatArray &global)
185{
186#ifdef __MPI_PARALLEL_MODE
187 if ( emodel->isParallel() ) {
188 int size = local.giveSize();
189 global.resize(size);
191 MPI_Allreduce( local.givePointer(), global.givePointer(), size, MPI_DOUBLE, MPI_SUM, this->emodel->giveParallelComm() );
192 } else {
193#endif
194 global = local;
195#ifdef __MPI_PARALLEL_MODE
196}
197#endif
198}
199} // end namespace oofem
double computeNorm() const
Definition floatarray.C:861
void resize(Index s)
Definition floatarray.C:94
double dotProduct(const FloatArray &x) const
Definition floatarray.C:524
Index giveSize() const
Returns the size of receiver.
Definition floatarray.h:261
const double * givePointer() const
Definition floatarray.h:506
Natural2GlobalOrdering n2g
Natural2LocalOrdering n2l
Natural2LocalOrdering * giveN2Lmap()

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