1 |
/* $Id$ */ |
2 |
|
3 |
/**************************************************************/ |
4 |
|
5 |
/* Some utility routines: */ |
6 |
|
7 |
/**************************************************************/ |
8 |
|
9 |
/* Copyrights by ACcESS Australia, 2003,2004,2005 */ |
10 |
|
11 |
/**************************************************************/ |
12 |
|
13 |
#include "Common.h" |
14 |
#include "Util.h" |
15 |
#ifdef _OPENMP |
16 |
#include <omp.h> |
17 |
#endif |
18 |
|
19 |
/* returns true if array contains value */ |
20 |
bool_t Paso_Util_isAny(dim_t N,index_t* array,index_t value) { |
21 |
bool_t out=FALSE; |
22 |
dim_t i; |
23 |
#pragma omp parallel for private(i) schedule(static) reduction(||:out) |
24 |
for (i=0;i<N;i++) out = out || (array[i]==value); |
25 |
return out; |
26 |
} |
27 |
|
28 |
|
29 |
/* copies source to taget: */ |
30 |
void Paso_copyDouble(dim_t n,double* source, double* target) { |
31 |
dim_t i; |
32 |
for (i=0;i<n;i++) target[i]=source[i]; |
33 |
} |
34 |
|
35 |
/**************************************************************/ |
36 |
|
37 |
/* calculates the cummultative sum in array and returns the total sum */ |
38 |
|
39 |
/**************************************************************/ |
40 |
index_t Paso_Util_cumsum(dim_t N,index_t* array) { |
41 |
index_t out=0,tmp; |
42 |
dim_t i; |
43 |
#ifdef _OPENMP |
44 |
index_t partial_sums[omp_get_max_threads()],sum; |
45 |
#pragma omp parallel private(sum,i,tmp) |
46 |
{ |
47 |
sum=0; |
48 |
#pragma omp for schedule(static) |
49 |
for (i=0;i<N;++i) sum+=array[i]; |
50 |
partial_sums[omp_get_thread_num()]=sum; |
51 |
#pragma omp barrier |
52 |
#pragma omp master |
53 |
{ |
54 |
out=0; |
55 |
for (i=0;i<omp_get_max_threads();++i) { |
56 |
tmp=out; |
57 |
out+=partial_sums[i]; |
58 |
partial_sums[i]=tmp; |
59 |
} |
60 |
} |
61 |
#pragma omp barrier |
62 |
sum=partial_sums[omp_get_thread_num()]; |
63 |
#pragma omp for schedule(static) |
64 |
for (i=0;i<N;++i) { |
65 |
tmp=sum; |
66 |
sum+=array[i]; |
67 |
array[i]=tmp; |
68 |
} |
69 |
} |
70 |
#else |
71 |
for (i=0;i<N;++i) { |
72 |
tmp=out; |
73 |
out+=array[i]; |
74 |
array[i]=tmp; |
75 |
} |
76 |
#endif |
77 |
return out; |
78 |
} |
79 |
|
80 |
/* |
81 |
* $Log$ |
82 |
* Revision 1.2 2005/09/15 03:44:39 jgs |
83 |
* Merge of development branch dev-02 back to main trunk on 2005-09-15 |
84 |
* |
85 |
* Revision 1.1.2.1 2005/09/05 06:29:48 gross |
86 |
* These files have been extracted from finley to define a stand alone libray for iterative |
87 |
* linear solvers on the ALTIX. main entry through Paso_solve. this version compiles but |
88 |
* has not been tested yet. |
89 |
* |
90 |
* |
91 |
*/ |