escript  Revision_4925
Distribution.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2014 by University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
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(Esys_MPIInfo* mpiInfo, const index_t* firstComponent,
45  index_t m, index_t b)
46  {
49  for (dim_t i=0; i < mpi_info->size+1; ++i)
50  first_component[i] = m*firstComponent[i]+b;
51  }
52 
54  {
56  delete[] first_component;
57  }
58 
59  inline index_t getFirstComponent() const
60  {
61  return first_component[mpi_info->rank];
62  }
63 
64  inline index_t getLastComponent() const
65  {
66  return first_component[mpi_info->rank+1];
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:64
#define PASO_DLL_API
Definition: Paso.h:41
void Esys_MPIInfo_free(Esys_MPIInfo *in)
Definition: Esys_MPI.cpp:60
Struct that holds MPI communicator, rank, size and a tag counter.
Definition: Esys_MPI.h:48
dim_t getGlobalNumComponents() const
Definition: Distribution.h:69
int size
Definition: Esys_MPI.h:50
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:32
Esys_MPI_rank rank
Definition: Esys_MPI.h:51
dim_t getMinGlobalComponents() const
Definition: Distribution.h:79
dim_t getMyNumComponents() const
Definition: Distribution.h:74
index_t * first_component
Definition: Distribution.h:126
MPI_Comm comm
Definition: Esys_MPI.h:52
Distribution(Esys_MPIInfo *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:59
Esys_MPIInfo * Esys_MPIInfo_getReference(Esys_MPIInfo *in)
Definition: Esys_MPI.cpp:67
int index_t
Definition: types.h:25
boost::shared_ptr< const Distribution > const_Distribution_ptr
Definition: Distribution.h:38
~Distribution()
Definition: Distribution.h:53
Esys_MPIInfo * mpi_info
Definition: Distribution.h:128
describes the distribution of a vector stored on the local process
Definition: Distribution.h:42
int dim_t
Definition: types.h:24
dim_t reference_counter
Definition: Distribution.h:127