Toggle navigation
Documentation
Big picture
The finite element method
The data structure
Not-so-quick guide
Optimisation
Order of action functions
Example codes and tutorials
List of example codes and tutorials
Meshing
Solvers
MPI parallel processing
Post-processing/visualisation
Other
Change log
Creating documentation
Coding conventions
Index
FAQ
Get it
Installation guide
Get code from subversion repository
Get code as tar file
Copyright
About
People
Contact/Get involved
Publications
Acknowledgements
Picture show
Go
src
generic
communicator.cc
Go to the documentation of this file.
1
//LIC// ====================================================================
2
//LIC// This file forms part of oomph-lib, the object-oriented,
3
//LIC// multi-physics finite-element library, available
4
//LIC// at http://www.oomph-lib.org.
5
//LIC//
6
//LIC// Version 1.0; svn revision $LastChangedRevision$
7
//LIC//
8
//LIC// $LastChangedDate$
9
//LIC//
10
//LIC// Copyright (C) 2006-2016 Matthias Heil and Andrew Hazel
11
//LIC//
12
//LIC// This library is free software; you can redistribute it and/or
13
//LIC// modify it under the terms of the GNU Lesser General Public
14
//LIC// License as published by the Free Software Foundation; either
15
//LIC// version 2.1 of the License, or (at your option) any later version.
16
//LIC//
17
//LIC// This library is distributed in the hope that it will be useful,
18
//LIC// but WITHOUT ANY WARRANTY; without even the implied warranty of
19
//LIC// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
//LIC// Lesser General Public License for more details.
21
//LIC//
22
//LIC// You should have received a copy of the GNU Lesser General Public
23
//LIC// License along with this library; if not, write to the Free Software
24
//LIC// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25
//LIC// 02110-1301 USA.
26
//LIC//
27
//LIC// The authors may be contacted at oomph-lib@maths.man.ac.uk.
28
//LIC//
29
//LIC//====================================================================
30
// Functions for OomphCommunicator
31
32
// MPI headers
33
#ifdef OOMPH_HAS_MPI
34
#include "mpi.h"
35
#endif
36
37
// Oomph-lib error handler
38
#include "
communicator.h
"
39
#include "
matrices.h
"
40
41
namespace
oomph
{
42
43
#ifdef OOMPH_HAS_MPI
44
45
//=============================================================================
46
/// A broadcast function for DenseMatrix<double>
47
//=============================================================================
48
void
OomphCommunicator::broadcast(
const
int
& source, DenseMatrix<double>& x)
49
{
50
// Get number of entries on processor source (where the matrix exists)
51
unsigned
nrow,ncol;
52
if
(this->my_rank()==source)
53
{
54
nrow=x.nrow();
55
if
(nrow>0)
56
{ncol=x.ncol();}
57
else
58
{ncol=0;}
59
}
60
61
// Broadcast to everybody how many entries to expect
62
MPI_Bcast(&nrow,1,MPI_UNSIGNED_LONG,source,this->mpi_comm());
63
MPI_Bcast(&ncol,1,MPI_UNSIGNED_LONG,source,this->mpi_comm());
64
65
if
(ncol!=0 && nrow!=0)
66
{
67
// convert into a C-style array
68
double
* x_bcast=
new
double
[nrow*ncol];
69
70
if
(this->my_rank()==source)
71
for
(
unsigned
long
i
=0;
i
<nrow;
i
++)
72
{
73
for
(
unsigned
long
j=0;j<ncol;j++)
74
{
75
x_bcast[
i
*ncol+j]=x(
i
,j);
76
}
77
}
78
79
// broadcast the array
80
MPI_Bcast(x_bcast,ncol*nrow,MPI_DOUBLE,source,this->mpi_comm());
81
82
// Now convert back into matrix (everywhere apart from source)
83
if
(this->my_rank()!=source)
84
{
85
x.resize(nrow,ncol);
86
for
(
unsigned
long
i
=0;
i
<nrow;
i
++)
87
for
(
unsigned
long
j=0;j<ncol;j++)
88
{
89
x(
i
,j)=x_bcast[
i
*ncol+j];
90
}
91
}
92
// delete C-style array
93
delete
[] x_bcast;
94
}
95
else
96
{
97
x.resize(0,0);
98
}
99
}
100
101
#endif
102
103
}
// end of oomph namespace
matrices.h
i
cstr elem_len * i
Definition:
cfortran.h:607
oomph
Definition:
advection_diffusion_elements.cc:33
communicator.h