escript  Revision_
SharedComponents.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2016 by The University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Apache License, version 2.0
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16 
17 
18 /****************************************************************************/
19 
20 /* Paso: shared components */
21 
22 /****************************************************************************/
23 
24 /* Author: Lutz Gross, l.gross@uq.edu.au */
25 
26 /****************************************************************************/
27 
28 #ifndef __PASO_SHAREDCOMPONENTS_H__
29 #define __PASO_SHAREDCOMPONENTS_H__
30 
31 #include "Paso.h"
32 
33 namespace paso {
34 
36 typedef boost::shared_ptr<SharedComponents> SharedComponents_ptr;
37 typedef boost::shared_ptr<const SharedComponents> const_SharedComponents_ptr;
38 
41 {
42  SharedComponents(dim_t localLength, const std::vector<int>& neighbours,
43  const index_t* sharedArray,
44  const std::vector<index_t>& offset,
45  index_t m = 1, index_t b = 0)
46  : local_length(localLength*m),
47  neighbour(neighbours),
48  offsetInShared(offset)
49  {
50  if (offset.empty()) {
52  } else {
53  numSharedComponents = offset[neighbours.size()] * m;
54  }
56  if (!neighbours.empty() && !offset.empty()) {
57  if (m != 1) {
58  for (int i = 0; i < offsetInShared.size(); i++) {
59  offsetInShared[i] *= m;
60  }
61  }
62 #pragma omp parallel for
63  for (dim_t i = 0; i < offset[neighbours.size()]; i++) {
64  const index_t itmp = m * sharedArray[i] + b;
65  for (dim_t j = 0; j < m; ++j)
66  shared[m*i+j] = itmp+j;
67  }
68  } else {
69  offsetInShared[neighbours.size()] = 0;
70  }
71  }
72 
74  {
75  delete[] shared;
76  }
77 
80 
82  std::vector<int> neighbour;
83 
86  std::vector<index_t> offsetInShared;
87 
91 
94 };
95 
96 } // namespace paso
97 
98 #endif // __PASO_SHAREDCOMPONENTS_H__
99 
SharedComponents(dim_t localLength, const std::vector< int > &neighbours, const index_t *sharedArray, const std::vector< index_t > &offset, index_t m=1, index_t b=0)
Definition: SharedComponents.h:42
#define PASO_DLL_API
Definition: Paso.h:58
~SharedComponents()
Definition: SharedComponents.h:73
boost::shared_ptr< const SharedComponents > const_SharedComponents_ptr
Definition: SharedComponents.h:37
boost::shared_ptr< SharedComponents > SharedComponents_ptr
Definition: SharedComponents.h:35
std::vector< index_t > offsetInShared
Definition: SharedComponents.h:86
dim_t local_length
local array length shared
Definition: SharedComponents.h:79
Definition: AMG.cpp:45
int index_t
type for array/matrix indices used both globally and on each rank
Definition: DataTypes.h:59
dim_t numSharedComponents
= offsetInShared[numNeighbours]
Definition: SharedComponents.h:93
std::vector< int > neighbour
list of the processors sharing values with this processor
Definition: SharedComponents.h:82
Definition: SharedComponents.h:40
index_t * shared
Definition: SharedComponents.h:90
index_t dim_t
Definition: DataTypes.h:64