/[escript]/trunk/paso/src/Distribution.c
ViewVC logotype

Contents of /trunk/paso/src/Distribution.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3482 - (show annotations)
Wed Mar 23 04:06:52 2011 UTC (8 years, 5 months ago) by gross
File MIME type: text/plain
File size: 4416 byte(s)
some work on AMG MPI
1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2010 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14
15 /**************************************************************/
16
17 /* Paso: system matrix pattern */
18
19 /**************************************************************/
20
21 /* Author: Lutz Gross, l.gross@uq.edu.au */
22
23 /**************************************************************/
24
25 #include "Distribution.h"
26 #include "PasoUtil.h"
27 #include "esysUtils/error.h" /* For checkPtr */
28
29 Paso_Distribution* Paso_Distribution_alloc( Esys_MPIInfo *mpi_info,
30 index_t *first_component,
31 index_t m, index_t b)
32 {
33 int i;
34 Paso_Distribution *out=NULL;
35 out = MEMALLOC( 1, Paso_Distribution );
36 if (Esys_checkPtr(out)) return NULL;
37 out->mpi_info = Esys_MPIInfo_getReference(mpi_info);
38 out->reference_counter = 0;
39 out->first_component=NULL;
40
41 out->first_component = MEMALLOC( (mpi_info->size)+1, index_t );
42 if (Esys_checkPtr(out->first_component)) {
43 Paso_Distribution_free(out);
44 return NULL;
45 }
46 for (i=0; i<(mpi_info->size)+1; ++i) out->first_component[i]=m*first_component[i]+b;
47 out->reference_counter++;
48 return out;
49 }
50
51 void Paso_Distribution_free( Paso_Distribution *in )
52 {
53 if (in != NULL) {
54 --(in->reference_counter);
55 if (in->reference_counter<=0) {
56 Esys_MPIInfo_free( in->mpi_info );
57 MEMFREE( in->first_component );
58 MEMFREE( in );
59 }
60 }
61 }
62
63 Paso_Distribution* Paso_Distribution_getReference( Paso_Distribution *in )
64 {
65 if ( in != NULL)
66 in->reference_counter++;
67 return in;
68 }
69
70 index_t Paso_Distribution_getFirstComponent(Paso_Distribution *in ) {
71 if (in !=NULL) {
72 return in->first_component[in->mpi_info->rank];
73 } else {
74 return 0;
75 }
76 }
77 index_t Paso_Distribution_getLastComponent(Paso_Distribution *in ){
78 if (in !=NULL) {
79 return in->first_component[(in->mpi_info->rank)+1];
80 } else {
81 return 0;
82 }
83 }
84
85 dim_t Paso_Distribution_getGlobalNumComponents(Paso_Distribution *in ){
86 return Paso_Distribution_getMaxGlobalComponents(in)-Paso_Distribution_getMinGlobalComponents(in);
87 }
88 dim_t Paso_Distribution_getMyNumComponents(Paso_Distribution *in ) {
89 return Paso_Distribution_getLastComponent(in)-Paso_Distribution_getFirstComponent(in);
90 }
91
92 dim_t Paso_Distribution_getMinGlobalComponents(Paso_Distribution *in ){
93 if (in !=NULL) {
94 return in->first_component[0];
95 } else {
96 return 0;
97 }
98 }
99 dim_t Paso_Distribution_getMaxGlobalComponents(Paso_Distribution *in ){
100 if (in !=NULL) {
101 return in->first_component[in->mpi_info->size];
102 } else {
103 return 0;
104 }
105 }
106
107 /* Pseudo random numbers such that the values are independend from
108 the distribution but the global length yet :*/
109
110 static double Paso_Distribution_random_seed=.4142135623730951;
111
112 double* Paso_Distribution_createRandomVector(Paso_Distribution *in, const dim_t block )
113 {
114
115 index_t i;
116 double *out=NULL;
117 const index_t n_0 = in->first_component[in->mpi_info->rank] * block;
118 const index_t n_1 = in->first_component[in->mpi_info->rank+1] * block;
119 const index_t n = ( Paso_Distribution_getMaxGlobalComponents(in)-Paso_Distribution_getMinGlobalComponents(in) ) * block;
120 const dim_t my_n = n_1-n_0;
121
122 out=MEMALLOC(my_n , double);
123
124 #pragma omp parallel for private(i) schedule(static)
125 for (i=0; i<my_n ;++i) {
126 out[i]=fmod( Paso_Distribution_random_seed*(n_0+i+1) ,1.);
127 }
128
129 Paso_Distribution_random_seed=fmod( Paso_Distribution_random_seed * (n+1), 1.);
130
131 return out;
132 }
133
134 dim_t Paso_Distribution_numPositives(const double* x, const Paso_Distribution *in, const dim_t block )
135 {
136
137 dim_t my_out, out;
138 const index_t n_0 = in->first_component[in->mpi_info->rank] * block;
139 const index_t n_1 = in->first_component[in->mpi_info->rank+1] * block;
140 const dim_t my_n = n_1-n_0;
141
142
143 my_out = Paso_Util_numPositives(my_n, x);
144
145 #ifdef ESYS_MPI
146 #pragma omp single
147 {
148 MPI_Allreduce(&my_out,&out, 1, MPI_INT, MPI_SUM, in->mpi_info->comm);
149 }
150 #else
151 out=my_out;
152 #endif
153
154 return out;
155 }

  ViewVC Help
Powered by ViewVC 1.1.26