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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1556 - (show annotations)
Mon May 12 00:54:58 2008 UTC (11 years, 8 months ago) by gross
File MIME type: text/plain
File size: 2786 byte(s)
Modification to allow mixed mode execution. 
In order to keep the code portable accross platform all MPI calls within
parallel regions have been moved. 


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[omp_get_max_threads()],sum;
58 #pragma omp parallel private(sum,i,tmp)
59 {
60 sum=0;
61 #pragma omp for schedule(static)
62 for (i=0;i<N;++i) sum+=array[i];
63 partial_sums[omp_get_thread_num()]=sum;
64 #pragma omp barrier
65 #pragma omp single
66 {
67 out=0;
68 for (i=0;i<omp_get_max_threads();++i) {
69 tmp=out;
70 out+=partial_sums[i];
71 partial_sums[i]=tmp;
72 }
73 }
74 sum=partial_sums[omp_get_thread_num()];
75 #pragma omp for schedule(static)
76 for (i=0;i<N;++i) {
77 tmp=sum;
78 sum+=array[i];
79 array[i]=tmp;
80 }
81 }
82 #else
83 for (i=0;i<N;++i) {
84 tmp=out;
85 out+=array[i];
86 array[i]=tmp;
87 }
88 #endif
89 return out;
90 }
91
92 /*
93 * $Log$
94 * Revision 1.2 2005/09/15 03:44:39 jgs
95 * Merge of development branch dev-02 back to main trunk on 2005-09-15
96 *
97 * Revision 1.1.2.1 2005/09/05 06:29:48 gross
98 * These files have been extracted from finley to define a stand alone libray for iterative
99 * linear solvers on the ALTIX. main entry through Paso_solve. this version compiles but
100 * has not been tested yet.
101 *
102 *
103 */

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26