escript  Revision_Unversioneddirectory
Distribution.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: distribution */
21 
22 /****************************************************************************/
23 
24 /* Author: Lutz Gross, l.gross@uq.edu.au */
25 
26 /****************************************************************************/
27 
28 #ifndef __PASO_DISTRIBUTION_H__
29 #define __PASO_DISTRIBUTION_H__
30 
31 #include "Paso.h"
32 #include "PasoUtil.h"
33 
34 namespace paso {
35 
36 struct Distribution;
37 typedef boost::shared_ptr<Distribution> Distribution_ptr;
38 typedef boost::shared_ptr<const Distribution> const_Distribution_ptr;
39 
43 {
44  Distribution(const esysUtils::JMPI& mpiInfo, const index_t* firstComponent,
45  index_t m, index_t b) :
46  mpi_info(mpiInfo)
47  {
48  first_component = new index_t[mpi_info->size+1];
49  for (dim_t i=0; i < mpi_info->size+1; ++i)
50  first_component[i] = m*firstComponent[i]+b;
51  }
52 
54  {
55  delete[] first_component;
56  }
57 
58  inline index_t getFirstComponent() const
59  {
60  return first_component[mpi_info->rank];
61  }
62 
63  inline index_t getLastComponent() const
64  {
65  return first_component[mpi_info->rank+1];
66  }
67 
68 
70  {
72  }
73 
74  inline dim_t getMyNumComponents() const
75  {
77  }
78 
80  {
81  return first_component[0];
82  }
83 
85  {
86  return first_component[mpi_info->size];
87  }
88 
89  inline dim_t numPositives(const double* x, dim_t block) const
90  {
91  const dim_t my_n = block * getMyNumComponents();
92  dim_t my_out = util::numPositives(my_n, x);
93  dim_t out;
94 
95 #ifdef ESYS_MPI
96 #pragma omp single
97  {
98  MPI_Allreduce(&my_out, &out, 1, MPI_INT, MPI_SUM, mpi_info->comm);
99  }
100 #else
101  out = my_out;
102 #endif
103  return out;
104  }
105 
106  inline double* createRandomVector(dim_t block) const
107  {
108  const index_t n_0 = getFirstComponent() * block;
109  const index_t n_1 = getLastComponent() * block;
110  const index_t n = getGlobalNumComponents() * block;
111  const dim_t my_n = n_1-n_0;
112 
113  double* out = new double[my_n];
114 
115 #pragma omp parallel for schedule(static)
116  for (index_t i=0; i<my_n; ++i) {
117  out[i]=fmod(random_seed*(n_0+i+1), 1.);
118  }
119 
120  random_seed = fmod(random_seed * (n+1.7), 1.);
121  return out;
122  }
123 
124  // process i has nodes with global indices first_component[i] to
125  // first_component[i+1].
129  static double random_seed;
130 };
131 
132 } // namespace paso
133 
134 #endif // __PASO_DISTRIBUTION_H__
135 
dim_t numPositives(const double *x, dim_t block) const
Definition: Distribution.h:89
index_t getLastComponent() const
Definition: Distribution.h:63
#define PASO_DLL_API
Definition: Paso.h:41
dim_t getGlobalNumComponents() const
Definition: Distribution.h:69
#define MPI_SUM
Definition: Esys_MPI.h:49
boost::shared_ptr< Distribution > Distribution_ptr
Definition: Distribution.h:36
dim_t numPositives(dim_t N, const double *x)
returns the number of positive values in x
Definition: PasoUtil.cpp:63
#define MPI_INT
Definition: Esys_MPI.h:42
dim_t getMinGlobalComponents() const
Definition: Distribution.h:79
dim_t getMyNumComponents() const
Definition: Distribution.h:74
Definition: AMG.cpp:38
index_t * first_component
Definition: Distribution.h:126
const esysUtils::JMPI mpi_info
Definition: Distribution.h:128
Distribution(const esysUtils::JMPI &mpiInfo, const index_t *firstComponent, index_t m, index_t b)
Definition: Distribution.h:44
double * createRandomVector(dim_t block) const
Definition: Distribution.h:106
dim_t getMaxGlobalComponents() const
Definition: Distribution.h:84
static double random_seed
Definition: Distribution.h:129
index_t getFirstComponent() const
Definition: Distribution.h:58
int index_t
Definition: types.h:24
boost::shared_ptr< const Distribution > const_Distribution_ptr
Definition: Distribution.h:38
~Distribution()
Definition: Distribution.h:53
index_t dim_t
Definition: types.h:27
describes the distribution of a vector stored on the local process
Definition: Distribution.h:42
boost::shared_ptr< JMPI_ > JMPI
Definition: Esys_MPI.h:79
dim_t reference_counter
Definition: Distribution.h:127