OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
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 - 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 "parallelcontext.h"
36 #include "engngm.h"
37 #include "mathfem.h"
38 #include "unknownnumberingscheme.h"
39 
40 namespace oofem {
41 //#define ParallelContext_debug_print
42 
44 #ifdef __PARALLEL_MODE
45  : n2g(), n2l()
46 #endif
47 {
48  this->emodel = e;
49 }
50 
52 { }
53 
54 void
56 {
57  di = newDi;
59 #ifdef __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 
74 int
76 {
77 #ifdef __PARALLEL_MODE
78  if ( emodel->isParallel() ) {
79  return n2g.giveNumberOfLocalEqs();
80  } else {
81 #endif
83 
84 #ifdef __PARALLEL_MODE
85 }
86 #endif
87 }
88 
89 
90 int
92 {
93 #ifdef __PARALLEL_MODE
94  if ( emodel->isParallel() ) {
95  return n2g.giveNumberOfGlobalEqs();
96  } else {
97 #endif
99 
100 #ifdef __PARALLEL_MODE
101 }
102 #endif
103 }
104 
105 int
107 {
109 }
110 
111 
112 bool
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 
126 double
128 {
129 #ifdef __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 
147 double
149 {
150 #ifdef __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 
168 double
170 {
171 #ifdef __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 
183 void
185 {
186 #ifdef __PARALLEL_MODE
187  if ( emodel->isParallel() ) {
188  int size = local.giveSize();
189  global.resize(size);
191  MPI_Allreduce( const_cast<double*>(local.givePointer()), global.givePointer(), size, MPI_DOUBLE, MPI_SUM, this->emodel->giveParallelComm() );
192  } else {
193 #endif
194  global = local;
195 #ifdef __PARALLEL_MODE
196 }
197 #endif
198 }
199 } // end namespace oofem
The representation of EngngModel default unknown numbering.
int giveNumberOfLocalEqs()
Returns number of local eqs; ie.
virtual int giveNumberOfDomainEquations(int di, const UnknownNumberingScheme &num)
Returns number of equations for given domain in active (current time step) time step.
Definition: engngm.C:391
bool isLocal(DofManager *dman)
virtual void init(EngngModel *, int di, const UnknownNumberingScheme &n)
Initiates the receiver.
void init(int newDi)
Initiates the mapping for given domain.
Ordering from oofem natural ordering (includes all local and shared eqs) to local ordering...
bool isParallel() const
Returns true if receiver in parallel mode.
Definition: engngm.h:1056
Base class for dof managers.
Definition: dofmanager.h:113
Natural2LocalOrdering * giveN2Lmap()
double localDotProduct(const FloatArray &a, const FloatArray &b)
Dot product for a locally distributed array.
double dotProduct(const FloatArray &x) const
Computes the dot product (or inner product) of receiver and argument.
Definition: floatarray.C:463
virtual void init(EngngModel *, int di, const UnknownNumberingScheme &n)
Initiates the receiver.
virtual int giveNewEq(int leq)
Finds the global equation from a local equation.
MPI_Comm giveParallelComm()
Returns the communication object of reciever.
Definition: engngm.h:549
Class representing vector of real numbers.
Definition: floatarray.h:82
double computeNorm() const
Computes the norm (or length) of the vector.
Definition: floatarray.C:840
int giveRank() const
Returns domain rank in a group of collaborating processes (0..groupSize-1)
Definition: engngm.h:1058
Natural2LocalOrdering n2l
Natural2GlobalOrdering n2g
const double * givePointer() const
Gives the pointer to the raw data, breaking encapsulation.
Definition: floatarray.h:469
double accumulate(double local)
Accumulates the global value.
Abstract base class representing the "problem" under consideration.
Definition: engngm.h:181
int giveSize() const
Returns the size of receiver.
Definition: floatarray.h:218
the oofem namespace is to define a context or scope in which all oofem names are defined.
double localNorm(const FloatArray &src)
Norm for a locally distributed array.
ParallelContext(EngngModel *e)
Creates a context belonging to a system of equations in a given engineering model.
void resize(int s)
Resizes receiver towards requested size.
Definition: floatarray.C:631

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:30 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011