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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1564 - (show annotations)
Thu May 22 09:31:33 2008 UTC (11 years, 5 months ago) by gross
File MIME type: text/plain
File size: 2864 byte(s)
some openmp dynamic scheduling for MVM.
1
2 /* $Id$ */
3
4 /*******************************************************
5 *
6 * Copyright 2003-2007 by ACceSS MNRF
7 * Copyright 2007 by University of Queensland
8 *
9 * http://esscc.uq.edu.au
10 * Primary Business: Queensland, Australia
11 * Licensed under the Open Software License version 3.0
12 * http://www.opensource.org/licenses/osl-3.0.php
13 *
14 *******************************************************/
15
16 /**************************************************************/
17
18 /* Some utility routines: */
19
20 /**************************************************************/
21
22 /* Copyrights by ACcESS Australia, 2003,2004,2005 */
23
24 /**************************************************************/
25
26 #include "Common.h"
27 #include "PasoUtil.h"
28 #ifdef _OPENMP
29 #include <omp.h>
30 #endif
31
32 /* returns true if array contains value */
33 bool_t Paso_Util_isAny(dim_t N,index_t* array,index_t value) {
34 bool_t out=FALSE;
35 dim_t i;
36 #pragma omp parallel for private(i) schedule(static) reduction(||:out)
37 for (i=0;i<N;i++) out = out || (array[i]==value);
38 return out;
39 }
40
41
42 /* copies source to taget: */
43 void Paso_copyDouble(dim_t n,double* source, double* target) {
44 dim_t i;
45 for (i=0;i<n;i++) target[i]=source[i];
46 }
47
48 /**************************************************************/
49
50 /* calculates the cummultative sum in array and returns the total sum */
51
52 /**************************************************************/
53 index_t Paso_Util_cumsum(dim_t N,index_t* array) {
54 index_t out=0,tmp;
55 dim_t i;
56 #ifdef _OPENMP
57 index_t *partial_sums=NULL,sum;
58 partial_sums=TMPMEMALLOC(omp_get_max_threads(),index_t);
59 #pragma omp parallel private(sum,i,tmp)
60 {
61 sum=0;
62 #pragma omp for schedule(static)
63 for (i=0;i<N;++i) sum+=array[i];
64 partial_sums[omp_get_thread_num()]=sum;
65 #pragma omp barrier
66 #pragma omp single
67 {
68 out=0;
69 for (i=0;i<omp_get_max_threads();++i) {
70 tmp=out;
71 out+=partial_sums[i];
72 partial_sums[i]=tmp;
73 }
74 }
75 sum=partial_sums[omp_get_thread_num()];
76 #pragma omp for schedule(static)
77 for (i=0;i<N;++i) {
78 tmp=sum;
79 sum+=array[i];
80 array[i]=tmp;
81 }
82 }
83 TMPMEMFREE(partial_sums);
84 #else
85 for (i=0;i<N;++i) {
86 tmp=out;
87 out+=array[i];
88 array[i]=tmp;
89 }
90 #endif
91 return out;
92 }
93
94 /*
95 * $Log$
96 * Revision 1.2 2005/09/15 03:44:39 jgs
97 * Merge of development branch dev-02 back to main trunk on 2005-09-15
98 *
99 * Revision 1.1.2.1 2005/09/05 06:29:48 gross
100 * These files have been extracted from finley to define a stand alone libray for iterative
101 * linear solvers on the ALTIX. main entry through Paso_solve. this version compiles but
102 * has not been tested yet.
103 *
104 *
105 */

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26