~chaffra/+junk/trilinos

« back to all changes in this revision

Viewing changes to packages/phdmesh/include/mesh/FieldParallel.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme, Christophe Prud'homme, Johannes Ring
  • Date: 2009-12-13 12:53:22 UTC
  • mfrom: (5.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20091213125322-in0nrdjc55deqsw9
Tags: 10.0.3.dfsg-1
[Christophe Prud'homme]
* New upstream release

[Johannes Ring]
* debian/patches/libname.patch: Add prefix 'libtrilinos_' to all
  libraries. 
* debian/patches/soname.patch: Add soversion to libraries.
* debian/watch: Update download URL.
* debian/control:
  - Remove python-numeric from Build-Depends (virtual package).
  - Remove automake and autotools from Build-Depends and add cmake to
    reflect switch to CMake.
  - Add python-support to Build-Depends.
* debian/rules: 
  - Cleanup and updates for switch to CMake.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*------------------------------------------------------------------------*/
 
2
/*      phdMesh : Parallel Heterogneous Dynamic unstructured Mesh         */
 
3
/*                Copyright (2008) Sandia Corporation                     */
 
4
/*                                                                        */
 
5
/*  Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive   */
 
6
/*  license for use of this work by or on behalf of the U.S. Government.  */
 
7
/*                                                                        */
 
8
/*  This library is free software; you can redistribute it and/or modify  */
 
9
/*  it under the terms of the GNU Lesser General Public License as        */
 
10
/*  published by the Free Software Foundation; either version 2.1 of the  */
 
11
/*  License, or (at your option) any later version.                       */
 
12
/*                                                                        */
 
13
/*  This library is distributed in the hope that it will be useful,       */
 
14
/*  but WITHOUT ANY WARRANTY; without even the implied warranty of        */
 
15
/*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     */
 
16
/*  Lesser General Public License for more details.                       */
 
17
/*                                                                        */
 
18
/*  You should have received a copy of the GNU Lesser General Public      */
 
19
/*  License along with this library; if not, write to the Free Software   */
 
20
/*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307   */
 
21
/*  USA                                                                   */
 
22
/*------------------------------------------------------------------------*/
 
23
/**
 
24
 * @author H. Carter Edwards
 
25
 */
 
26
 
 
27
#ifndef phdmesh_FieldParallel_hpp
 
28
#define phdmesh_FieldParallel_hpp
 
29
 
 
30
//----------------------------------------------------------------------
 
31
 
 
32
#include <util/SimpleArrayOps.hpp>
 
33
#include <util/Parallel.hpp>
 
34
#include <util/ParallelComm.hpp>
 
35
 
 
36
#include <mesh/Types.hpp>
 
37
#include <mesh/Field.hpp>
 
38
#include <mesh/Entity.hpp>
 
39
#include <mesh/BulkData.hpp>
 
40
 
 
41
namespace phdmesh {
 
42
 
 
43
/** Communicate field data from domain to range.
 
44
 *  The fields array must be identical on all processors.
 
45
 *  All fields and mesh entities must belong to the same mesh.
 
46
 *  If symmetric ( & domain == & range) then from owned to not owned.
 
47
 */
 
48
bool communicate_field_data(
 
49
  const BulkData & mesh ,
 
50
  const std::vector<EntityProc> & domain ,
 
51
  const std::vector<EntityProc> & range ,
 
52
  const std::vector< const FieldBase *> & fields ,
 
53
  bool local_flag = false );
 
54
 
 
55
/** Communicate field data given symmetric communication plan.  */
 
56
void communicate_field_data(
 
57
  ParallelMachine ,
 
58
  const std::vector<EntityProc> & ,
 
59
  const unsigned field_count ,
 
60
  const FieldBase * fields[] ,
 
61
  CommAll & sparse );
 
62
 
 
63
//----------------------------------------------------------------------
 
64
 
 
65
namespace {
 
66
 
 
67
//----------------------------------------------------------------------
 
68
/** Parallel reduction of shared entities' field data.
 
69
 *  In the anonymous namespace to avoid redundant link symbols.
 
70
 *
 
71
 *  example usage:
 
72
 *    parallel_reduce( mesh , sum( field ) );
 
73
 *
 
74
 *  where the operations are: sum, max, min
 
75
 */
 
76
template< class OpField >
 
77
void parallel_reduce( const BulkData & mesh ,
 
78
                      const OpField      & op )
 
79
{
 
80
  const FieldBase * fields[1] = { & op.field };
 
81
 
 
82
  const std::vector<EntityProc> & shared = mesh.shared_entities();
 
83
 
 
84
  CommAll sparse ;
 
85
 
 
86
  communicate_field_data( mesh.parallel(), shared, 1, fields, sparse );
 
87
 
 
88
  op( shared , sparse );
 
89
}
 
90
 
 
91
/** Parallel reduction of shared entities' field data.
 
92
 *  In the anonymous namespace to avoid redundant link symbols.
 
93
 *
 
94
 *  example usage:
 
95
 *    parallel_reduce( mesh , sum( fieldA ) , max( fieldB ) );
 
96
 */
 
97
template< class OpField1 , class OpField2 >
 
98
void parallel_reduce( const BulkData & mesh ,
 
99
                      const OpField1     & op1 ,
 
100
                      const OpField2     & op2 )
 
101
{
 
102
  const FieldBase * fields[2] = { & op1.field , & op2.field };
 
103
 
 
104
  const std::vector<EntityProc> & shared = mesh.shared_entities();
 
105
 
 
106
  CommAll sparse ;
 
107
 
 
108
  communicate_field_data( mesh.parallel(), shared, 2, fields, sparse );
 
109
 
 
110
  op1( shared , sparse );
 
111
  op2( shared , sparse );
 
112
}
 
113
 
 
114
//----------------------------------------------------------------------
 
115
 
 
116
template< class ReduceOp ,
 
117
          class Type , class Tag1, class Tag2, class Tag3 ,
 
118
          class Tag4 , class Tag5, class Tag6, class Tag7 >
 
119
struct ParallelReduceField {
 
120
  typedef Field<Type,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7> field_type ;
 
121
 
 
122
  const field_type & field ;
 
123
 
 
124
  ParallelReduceField( const field_type & f ) : field(f) {}
 
125
  ParallelReduceField( const ParallelReduceField & p ) : field(p.field) {}
 
126
 
 
127
  void operator()( const std::vector<EntityProc> & shared ,
 
128
                   CommAll & sparse ) const ;
 
129
 
 
130
private:
 
131
  ParallelReduceField & operator = ( const ParallelReduceField & );
 
132
};
 
133
 
 
134
template< class ReduceOp ,
 
135
          class Type , class Tag1, class Tag2, class Tag3 ,
 
136
          class Tag4 , class Tag5, class Tag6, class Tag7 >
 
137
void ParallelReduceField< ReduceOp , Type ,  Tag1,  Tag2,  Tag3 ,
 
138
                                     Tag4 ,  Tag5,  Tag6,  Tag7 >::
 
139
  operator()( const std::vector<EntityProc> & shared , CommAll & sparse ) const
 
140
{
 
141
  typedef EntityArray< field_type > array_type ;
 
142
 
 
143
  for ( std::vector<EntityProc>::const_iterator
 
144
        i = shared.begin(); i != shared.end() ; ++i ) {
 
145
 
 
146
    array_type array( field , * i->first );
 
147
    Type * ptr           = array.contiguous_data();
 
148
    Type * const ptr_end = ptr + array.size();
 
149
 
 
150
    CommBuffer & b = sparse.recv_buffer( i->second );
 
151
 
 
152
    for ( ; ptr < ptr_end ; ++ptr ) {
 
153
      Type tmp ;
 
154
      b.template unpack<unsigned char>( (unsigned char *)(&tmp), sizeof(Type) );
 
155
      ReduceOp::op( ptr , & tmp );
 
156
    }
 
157
  }
 
158
}
 
159
 
 
160
}
 
161
 
 
162
//----------------------------------------------------------------------
 
163
 
 
164
template< class Type , class Tag1, class Tag2, class Tag3 ,
 
165
          class Tag4 , class Tag5, class Tag6, class Tag7 >
 
166
ParallelReduceField<impl::Sum<Type,1>,Type,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7>
 
167
inline
 
168
sum( const Field<Type,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7> & f )
 
169
{
 
170
  return ParallelReduceField<impl::Sum<Type,1>,
 
171
                             Type,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7>( f );
 
172
}
 
173
 
 
174
template< class Type , class Tag1, class Tag2, class Tag3 ,
 
175
          class Tag4 , class Tag5, class Tag6, class Tag7 >
 
176
ParallelReduceField<impl::Max<Type,1>,Type,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7>
 
177
inline
 
178
max( const Field<Type,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7> & f )
 
179
{
 
180
  return ParallelReduceField<impl::Max<Type,1>,
 
181
                             Type,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7>( f );
 
182
}
 
183
 
 
184
template< class Type , class Tag1, class Tag2, class Tag3 ,
 
185
          class Tag4 , class Tag5, class Tag6, class Tag7 >
 
186
ParallelReduceField<impl::Min<Type,1>,Type,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7>
 
187
inline
 
188
min( const Field<Type,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7> & f )
 
189
{
 
190
  return ParallelReduceField<impl::Min<Type,1>,
 
191
                             Type,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7>( f );
 
192
}
 
193
 
 
194
}
 
195
 
 
196
#endif
 
197