/[escript]/branches/domexper/dudley/src/Util.c
ViewVC logotype

Diff of /branches/domexper/dudley/src/Util.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/finley/src/Util.c revision 751 by bcumming, Mon Jun 26 01:46:34 2006 UTC branches/domexper/dudley/src/Util.c revision 3086 by jfenwick, Thu Aug 5 05:07:58 2010 UTC
# Line 1  Line 1 
 /*  
  ************************************************************  
  *          Copyright 2006 by ACcESS MNRF                   *  
  *                                                          *  
  *              http://www.access.edu.au                    *  
  *       Primary Business: Queensland, Australia            *  
  *  Licensed under the Open Software License version 3.0    *  
  *     http://www.opensource.org/licenses/osl-3.0.php       *  
  *                                                          *  
  ************************************************************  
 */  
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    
 /*   Some utility routines: */  
14    
15  /**************************************************************/  /**************************************************************/
16    
17  /*   author: gross@access.edu.au */  /*   Some utility routines: */
 /*   Version: $Id$ */  
18    
19  /**************************************************************/  /**************************************************************/
20    
 #include "Finley.h"  
21  #include "Util.h"  #include "Util.h"
22    
23  #ifdef _OPENMP  #ifdef _OPENMP
24  #include <omp.h>  #include <omp.h>
25  #endif  #endif
# Line 31  Line 28 
28    
29  /*   returns true if any of the values in the short array values is not equalt to Zero */  /*   returns true if any of the values in the short array values is not equalt to Zero */
30    
31  bool_t Finley_Util_anyNonZeroDouble(dim_t N, double* values) {  bool_t Dudley_Util_anyNonZeroDouble(dim_t N, double* values) {
32     dim_t q;     dim_t q;
33     for (q=0;q<N;++q) if (ABS(values[q])>0) return TRUE;     for (q=0;q<N;++q) if (ABS(values[q])>0) return TRUE;
34     return FALSE;     return FALSE;
# Line 42  bool_t Finley_Util_anyNonZeroDouble(dim_ Line 39  bool_t Finley_Util_anyNonZeroDouble(dim_
39    
40  /*        out(1:numData,1:len)=in(1:numData,index(1:len)) */  /*        out(1:numData,1:len)=in(1:numData,index(1:len)) */
41    
42  void Finley_Util_Gather_double(dim_t len,index_t* index,dim_t numData,double* in, double * out){  void Dudley_Util_Gather_double(dim_t len,index_t* index,dim_t numData,double* in, double * out){
43      dim_t s,i;      dim_t s,i;
44      for (s=0;s<len;s++) {      for (s=0;s<len;s++) {
45         for (i=0;i<numData;i++) {         for (i=0;i<numData;i++) {
# Line 58  void Finley_Util_Gather_double(dim_t len Line 55  void Finley_Util_Gather_double(dim_t len
55    
56  /*        out(1:numData,1:len)=in(1:numData,index(1:len)) */  /*        out(1:numData,1:len)=in(1:numData,index(1:len)) */
57    
58  void Finley_Util_Gather_int(dim_t len,index_t* index,dim_t numData, index_t* in, index_t * out){  void Dudley_Util_Gather_int(dim_t len,index_t* index,dim_t numData, index_t* in, index_t * out){
59      dim_t s,i;      dim_t s,i;
60      for (s=0;s<len;s++) {      for (s=0;s<len;s++) {
61         for (i=0;i<numData;i++) {         for (i=0;i<numData;i++) {
# Line 71  void Finley_Util_Gather_int(dim_t len,in Line 68  void Finley_Util_Gather_int(dim_t len,in
68    
69  /*   adds a vector in into out using and index. */  /*   adds a vector in into out using and index. */
70    
71  /*        out(1:numData,index(1:len))+=in(1:numData,1:len) */  /*        out(1:numData,index[p])+=in(1:numData,p) where p = {k=1...len , index[k]<upperBound}*/
72    
 void Finley_Util_AddScatter(dim_t len,index_t* index,dim_t numData,double* in,double * out){  
    dim_t i,s;  
    for (s=0;s<len;s++) {  
        for(i=0;i<numData;i++) {  
           #pragma omp atomic  
           out[INDEX2(i,index[s],numData)]+=in[INDEX2(i,s,numData)];  
        }  
    }  
 }  
73    
74  #ifdef PASO_MPI  void Dudley_Util_AddScatter(dim_t len,index_t* index,dim_t numData,double* in,double * out, index_t upperBound){
 /* same as AddScatter(), but checks that value index[] is below an upper bound upperBound before    
    addition. This is used to ensure that only the influence of local DOF is added */  
 /*        out(1:numData,index[p])+=in(1:numData,p)  
         where p = {k=1...len , index[k]<upperBound}*/  
 void Finley_Util_AddScatter_upperBound(dim_t len,index_t* index,dim_t numData,double* in,double * out, index_t upperBound){  
75     dim_t i,s;     dim_t i,s;
76     for (s=0;s<len;s++) {     for (s=0;s<len;s++) {
77         for(i=0;i<numData;i++) {         for(i=0;i<numData;i++) {
78            //#pragma omp atomic            if( index[s]<upperBound ) {
           if( index[s]<upperBound )  
79              out[INDEX2(i,index[s],numData)]+=in[INDEX2(i,s,numData)];              out[INDEX2(i,index[s],numData)]+=in[INDEX2(i,s,numData)];
80          }
81         }         }
82     }     }
83  }    }
   
   
 #endif  
84    
85  /*    multiplies two matrices */  /*    multiplies two matrices */
86    
87  /*          A(1:A1,1:A2)=B(1:A1,1:B2)*C(1:B2,1:A2) */  /*          A(1:A1,1:A2)=B(1:A1,1:B2)*C(1:B2,1:A2) */
88    
89  void Finley_Util_SmallMatMult(dim_t A1,dim_t A2, double* A, dim_t B2, double*B, double* C) {  void Dudley_Util_SmallMatMult(dim_t A1,dim_t A2, double* A, dim_t B2, double*B, double* C) {
90      dim_t i,j,s;      dim_t i,j,s;
91      for (i=0;i<A1*A2;i++) A[i]=0;      register double rtmp;
92         for (i=0;i<A1;i++) {         for (i=0;i<A1;i++) {
93            for (j=0;j<A2;j++) {            for (j=0;j<A2;j++) {
94               for (s=0;s<B2;s++) {               rtmp=0;
95                  A[INDEX2(i,j,A1)]+=B[INDEX2(i,s,A1)]*C[INDEX2(s,j,B2)];               for (s=0;s<B2;s++) rtmp+=B[INDEX2(i,s,A1)]*C[INDEX2(s,j,B2)];
96               }               A[INDEX2(i,j,A1)]=rtmp;
97            }            }
98         }         }
99  }  }
# Line 122  void Finley_Util_SmallMatMult(dim_t A1,d Line 102  void Finley_Util_SmallMatMult(dim_t A1,d
102    
103  /*        A(1:A1,1:A2,i)=B(1:A1,1:B2,i)*C(1:B2,1:A2,i) i=1,len */  /*        A(1:A1,1:A2,i)=B(1:A1,1:B2,i)*C(1:B2,1:A2,i) i=1,len */
104    
105  void Finley_Util_SmallMatSetMult(dim_t len,dim_t A1,dim_t A2, double* A, dim_t B2, double*B, double* C) {  void Dudley_Util_SmallMatSetMult(dim_t len,dim_t A1,dim_t A2, double* A, dim_t B2, double*B, double* C) {
106      dim_t q,i,j,s;      dim_t q,i,j,s;
107      for (i=0;i<A1*A2*len;i++) A[i]=0;      register double rtmp;
108      for (q=0;q<len;q++) {      for (q=0;q<len;q++) {
109         for (i=0;i<A1;i++) {         for (i=0;i<A1;i++) {
110            for (j=0;j<A2;j++) {            for (j=0;j<A2;j++) {
111               for (s=0;s<B2;s++) {               rtmp=0;
112                  A[INDEX3(i,j,q,A1,A2)]+=B[INDEX3(i,s,q,A1,B2)]*C[INDEX3(s,j,q,B2,A2)];               for (s=0;s<B2;s++) rtmp+=B[INDEX3(i,s,q,A1,B2)]*C[INDEX3(s,j,q,B2,A2)];
113               }               A[INDEX3(i,j,q, A1,A2)]=rtmp;
114              }
115           }
116        }
117    }
118    /*    multiplies a set of matries with a single matrix: */
119    
120    /*        A(1:A1,1:A2,i)=B(1:A1,1:B2,i)*C(1:B2,1:A2) i=1,len */
121    
122    void Dudley_Util_SmallMatSetMult1(dim_t len,dim_t A1,dim_t A2, double* A, dim_t B2, double*B, double* C) {
123        dim_t q,i,j,s;
124        register double rtmp;
125        for (q=0;q<len;q++) {
126           for (i=0;i<A1;i++) {
127              for (j=0;j<A2;j++) {
128                 rtmp=0;
129                 for (s=0;s<B2;s++) rtmp+=B[INDEX3(i,s,q, A1,B2)]*C[INDEX2(s,j,B2)];
130                 A[INDEX3(i,j,q,A1,A2)]=rtmp;
131            }            }
132         }         }
133      }      }
# Line 138  void Finley_Util_SmallMatSetMult(dim_t l Line 135  void Finley_Util_SmallMatSetMult(dim_t l
135  /*    inverts the set of dim x dim matrices A(:,:,1:len) with dim=1,2,3 */  /*    inverts the set of dim x dim matrices A(:,:,1:len) with dim=1,2,3 */
136  /*    the determinante is returned. */  /*    the determinante is returned. */
137    
138  void Finley_Util_InvertSmallMat(dim_t len,dim_t dim,double* A,double *invA, double* det){  void Dudley_Util_InvertSmallMat(dim_t len,dim_t dim,double* A,double *invA, double* det){
139     dim_t q;     dim_t q;
140     register double D,A11,A12,A13,A21,A22,A23,A31,A32,A33;     register double D,A11,A12,A13,A21,A22,A23,A31,A32,A33;
141    
# Line 151  void Finley_Util_InvertSmallMat(dim_t le Line 148  void Finley_Util_InvertSmallMat(dim_t le
148                 D=1./D;                 D=1./D;
149                 invA[q]=D;                 invA[q]=D;
150              } else {              } else {
151                 Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: Non-regular matrix");                 Dudley_setError(ZERO_DIVISION_ERROR,"__FILE__: Non-regular matrix");
152                 return;                 return;
153              }              }
154           }           }
# Line 173  void Finley_Util_InvertSmallMat(dim_t le Line 170  void Finley_Util_InvertSmallMat(dim_t le
170                 invA[INDEX3(0,1,q,2,2)]=-A12*D;                 invA[INDEX3(0,1,q,2,2)]=-A12*D;
171                 invA[INDEX3(1,1,q,2,2)]= A11*D;                 invA[INDEX3(1,1,q,2,2)]= A11*D;
172              } else {              } else {
173                 Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: Non-regular matrix");                 Dudley_setError(ZERO_DIVISION_ERROR,"__FILE__: Non-regular matrix");
174                 return;                 return;
175              }              }
176           }           }
# Line 205  void Finley_Util_InvertSmallMat(dim_t le Line 202  void Finley_Util_InvertSmallMat(dim_t le
202                 invA[INDEX3(1,2,q,3,3)]=(A13*A21-A11*A23)*D;                 invA[INDEX3(1,2,q,3,3)]=(A13*A21-A11*A23)*D;
203                 invA[INDEX3(2,2,q,3,3)]=(A11*A22-A12*A21)*D;                 invA[INDEX3(2,2,q,3,3)]=(A11*A22-A12*A21)*D;
204              } else {              } else {
205                 Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: Non-regular matrix");                 Dudley_setError(ZERO_DIVISION_ERROR,"__FILE__: Non-regular matrix");
206                 return;                 return;
207              }              }
208           }           }
# Line 217  void Finley_Util_InvertSmallMat(dim_t le Line 214  void Finley_Util_InvertSmallMat(dim_t le
214    
215  /*    sets the derterminate of a set of dim x dim matrices A(:,:,1:len) with dim=1,2,3 */  /*    sets the derterminate of a set of dim x dim matrices A(:,:,1:len) with dim=1,2,3 */
216    
217  void Finley_Util_DetOfSmallMat(dim_t len,dim_t dim,double* A, double* det){  void Dudley_Util_DetOfSmallMat(dim_t len,dim_t dim,double* A, double* det){
218     dim_t q;     dim_t q;
219     register double A11,A12,A13,A21,A22,A23,A31,A32,A33;     register double A11,A12,A13,A21,A22,A23,A31,A32,A33;
220    
# Line 261  void Finley_Util_DetOfSmallMat(dim_t len Line 258  void Finley_Util_DetOfSmallMat(dim_t len
258  /*    returns the normalized vector Normal[dim,len] orthogonal to A(:,0,q) and A(:,1,q) in the case of dim=3  */  /*    returns the normalized vector Normal[dim,len] orthogonal to A(:,0,q) and A(:,1,q) in the case of dim=3  */
259  /*    or the vector A(:,0,q) in the case of dim=2                                             */  /*    or the vector A(:,0,q) in the case of dim=2                                             */
260    
261  void  Finley_NormalVector(dim_t len, dim_t dim, dim_t dim1, double* A,double* Normal) {  void  Dudley_NormalVector(dim_t len, dim_t dim, dim_t dim1, double* A,double* Normal) {
262     dim_t q;     dim_t q;
263     register double A11,A12,CO_A13,A21,A22,CO_A23,A31,A32,CO_A33,length,invlength;     register double A11,A12,CO_A13,A21,A22,CO_A23,A31,A32,CO_A33,length,invlength;
264    
# Line 275  void  Finley_NormalVector(dim_t len, dim Line 272  void  Finley_NormalVector(dim_t len, dim
272              A21=A[INDEX3(1,0,q,2,dim1)];              A21=A[INDEX3(1,0,q,2,dim1)];
273              length = sqrt(A11*A11+A21*A21);              length = sqrt(A11*A11+A21*A21);
274              if (! length>0) {              if (! length>0) {
275                 Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: area equals zero.");                 Dudley_setError(ZERO_DIVISION_ERROR,"__FILE__: area equals zero.");
276                 return;                 return;
277              } else {              } else {
278                 invlength=1./length;                 invlength=1./length;
# Line 297  void  Finley_NormalVector(dim_t len, dim Line 294  void  Finley_NormalVector(dim_t len, dim
294              CO_A33=A11*A22-A21*A12;              CO_A33=A11*A22-A21*A12;
295              length=sqrt(CO_A13*CO_A13+CO_A23*CO_A23+CO_A33*CO_A33);              length=sqrt(CO_A13*CO_A13+CO_A23*CO_A23+CO_A33*CO_A33);
296              if (! length>0) {              if (! length>0) {
297                 Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: area equals zero.");                 Dudley_setError(ZERO_DIVISION_ERROR,"__FILE__: area equals zero.");
298                 return;                 return;
299              } else {              } else {
300                 invlength=1./length;                 invlength=1./length;
# Line 316  void  Finley_NormalVector(dim_t len, dim Line 313  void  Finley_NormalVector(dim_t len, dim
313  /*    return the length of the vector which is orthogonal to the vectors A(:,0,q) and A(:,1,q) in the case of dim=3 */  /*    return the length of the vector which is orthogonal to the vectors A(:,0,q) and A(:,1,q) in the case of dim=3 */
314  /*    or the vector A(:,0,q) in the case of dim=2                                                                   */  /*    or the vector A(:,0,q) in the case of dim=2                                                                   */
315    
316  void  Finley_LengthOfNormalVector(dim_t len, dim_t dim, dim_t dim1, double* A,double* length) {  void  Dudley_LengthOfNormalVector(dim_t len, dim_t dim, dim_t dim1, double* A,double* length) {
317     dim_t q;     dim_t q;
318     double A11,A12,CO_A13,A21,A22,CO_A23,A31,A32,CO_A33;     double A11,A12,CO_A13,A21,A22,CO_A23,A31,A32,CO_A33;
319    
# Line 354  void  Finley_LengthOfNormalVector(dim_t Line 351  void  Finley_LengthOfNormalVector(dim_t
351  /* there is no range checking! */  /* there is no range checking! */
352  /* at output Map[invMap[i]]=i for i=0:lenInvMap */  /* at output Map[invMap[i]]=i for i=0:lenInvMap */
353    
354  void Finley_Util_InvertMap(dim_t lenInvMap, index_t* invMap,dim_t lenMap, index_t* Map) {  void Dudley_Util_InvertMap(dim_t lenInvMap, index_t* invMap,dim_t lenMap, index_t* Map) {
355     dim_t i;     dim_t i;
356     for (i=0;i<lenInvMap;i++) invMap[i]=0;     for (i=0;i<lenInvMap;i++) invMap[i]=0;
357     for (i=0;i<lenMap;i++) {     for (i=0;i<lenMap;i++) {
# Line 362  void Finley_Util_InvertMap(dim_t lenInvM Line 359  void Finley_Util_InvertMap(dim_t lenInvM
359     }     }
360  }  }
361    
362  /* orders a Finley_Util_ValueAndIndex array by value */  /* orders a Dudley_Util_ValueAndIndex array by value */
363  /* it is assumed that n is large */  /* it is assumed that n is large */
364    
365  int Finley_Util_ValueAndIndex_compar(const void *arg1 , const void *arg2 ) {  int Dudley_Util_ValueAndIndex_compar(const void *arg1 , const void *arg2 ) {
366     Finley_Util_ValueAndIndex *e1,*e2;     Dudley_Util_ValueAndIndex *e1,*e2;
367     e1=(Finley_Util_ValueAndIndex*) arg1;     e1=(Dudley_Util_ValueAndIndex*) arg1;
368     e2=(Finley_Util_ValueAndIndex*) arg2;     e2=(Dudley_Util_ValueAndIndex*) arg2;
369     if (e1->value < e2->value) return -1;     if (e1->value < e2->value) return -1;
370     if (e1->value > e2->value) return  1;     if (e1->value > e2->value) return  1;
371       if (e1->index < e2->index) return -1;
372       if (e1->index > e2->index) return  1;
373     return 0;     return 0;
374  }  }
375  void Finley_Util_sortValueAndIndex(dim_t n,Finley_Util_ValueAndIndex* array) {  
376    void Dudley_Util_sortValueAndIndex(dim_t n,Dudley_Util_ValueAndIndex* array) {
377       /* OMP : needs parallelization !*/       /* OMP : needs parallelization !*/
378       qsort(array,n,sizeof(Finley_Util_ValueAndIndex),Finley_Util_ValueAndIndex_compar);       qsort(array,n,sizeof(Dudley_Util_ValueAndIndex),Dudley_Util_ValueAndIndex_compar);
379  }  }
380    
381    
# Line 383  void Finley_Util_sortValueAndIndex(dim_t Line 383  void Finley_Util_sortValueAndIndex(dim_t
383    
384  /* calculates the minimum value from a dim X N integer array */  /* calculates the minimum value from a dim X N integer array */
385    
386  index_t Finley_Util_getMinInt(dim_t dim,dim_t N,index_t* values) {  index_t Dudley_Util_getMinInt(dim_t dim,dim_t N,index_t* values) {
387     dim_t i,j;     dim_t i,j;
388     index_t out,out_local;     index_t out,out_local;
389     out=INDEX_T_MAX;     out=INDEX_T_MAX;
# Line 405  index_t Finley_Util_getMinInt(dim_t dim, Line 405  index_t Finley_Util_getMinInt(dim_t dim,
405                                                                                                                                                                                                                                                                                                        
406  /* calculates the maximum value from a dim X N integer array */  /* calculates the maximum value from a dim X N integer array */
407    
408  index_t Finley_Util_getMaxInt(dim_t dim,dim_t N,index_t* values) {  index_t Dudley_Util_getMaxInt(dim_t dim,dim_t N,index_t* values) {
409     dim_t i,j;     dim_t i,j;
410     index_t out,out_local;     index_t out,out_local;
411     out=-INDEX_T_MAX;     out=-INDEX_T_MAX;
# Line 424  index_t Finley_Util_getMaxInt(dim_t dim, Line 424  index_t Finley_Util_getMaxInt(dim_t dim,
424     }     }
425     return out;     return out;
426  }  }
427    /**************************************************************/
428    
429    /* calculates the minimum value from a dim X N integer array */
430    
431    index_t Dudley_Util_getFlaggedMinInt(dim_t dim,dim_t N,index_t* values, index_t ignore) {
432       dim_t i,j;
433       index_t out,out_local;
434       out=INDEX_T_MAX;
435       if (values!=NULL && dim*N>0 ) {
436         out=values[0];
437         #pragma omp parallel private(out_local)
438         {
439             out_local=out;
440             #pragma omp for private(i,j) schedule(static)
441             for (j=0;j<N;j++) {
442               for (i=0;i<dim;i++) if (values[INDEX2(i,j,dim)]!=ignore) out_local=MIN(out_local,values[INDEX2(i,j,dim)]);
443             }
444             #pragma omp critical
445             out=MIN(out_local,out);
446         }
447       }
448       return out;
449    }
450                                                                                                                                                      
451    /* calculates the maximum value from a dim X N integer array */
452    
453    index_t Dudley_Util_getFlaggedMaxInt(dim_t dim,dim_t N,index_t* values, index_t ignore) {
454       dim_t i,j;
455       index_t out,out_local;
456       out=-INDEX_T_MAX;
457       if (values!=NULL && dim*N>0 ) {
458         out=values[0];
459         #pragma omp parallel private(out_local)
460         {
461             out_local=out;
462             #pragma omp for private(i,j) schedule(static)
463             for (j=0;j<N;j++) {
464                 for (i=0;i<dim;i++) if (values[INDEX2(i,j,dim)]!=ignore) out_local=MAX(out_local,values[INDEX2(i,j,dim)]);
465             }
466             #pragma omp critical
467             out=MAX(out_local,out);
468          }
469       }
470       return out;
471    }
472    
473  /* set the index of the positive entries in mask. The length of index is returned. */  /* set the index of the positive entries in mask. The length of index is returned. */
474    
475  dim_t Finley_Util_packMask(dim_t N,index_t* mask,index_t* index) {  dim_t Dudley_Util_packMask(dim_t N,index_t* mask,index_t* index) {
476        dim_t out,k;        dim_t out,k;
477        out=0;        out=0;
478        /*OMP */        /*OMP */
# Line 441  dim_t Finley_Util_packMask(dim_t N,index Line 486  dim_t Finley_Util_packMask(dim_t N,index
486  }  }
487    
488  /* returns true if array contains value */  /* returns true if array contains value */
489  bool_t Finley_Util_isAny(dim_t N,index_t* array,index_t value) {  bool_t Dudley_Util_isAny(dim_t N,index_t* array,index_t value) {
490     bool_t out=FALSE;     bool_t out=FALSE;
491     dim_t i;     dim_t i;
492     #pragma omp parallel for private(i) schedule(static) reduction(||:out)     #pragma omp parallel for private(i) schedule(static) reduction(||:out)
# Line 449  bool_t Finley_Util_isAny(dim_t N,index_t Line 494  bool_t Finley_Util_isAny(dim_t N,index_t
494     return out;     return out;
495  }  }
496  /* calculates the cummultative sum in array and returns the total sum */  /* calculates the cummultative sum in array and returns the total sum */
497  index_t Finley_Util_cumsum(dim_t N,index_t* array) {  index_t Dudley_Util_cumsum(dim_t N,index_t* array) {
498     index_t out=0,tmp;     index_t out=0,tmp;
499     dim_t i;     dim_t i;
500     #ifdef _OPENMP     #ifdef _OPENMP
501        index_t partial_sums[omp_get_max_threads()],sum;        index_t *partial_sums=NULL, sum;
502          partial_sums=TMPMEMALLOC(omp_get_max_threads(),index_t);
503        #pragma omp parallel private(sum,i,tmp)        #pragma omp parallel private(sum,i,tmp)
504        {        {
505          sum=0;          sum=0;
# Line 479  index_t Finley_Util_cumsum(dim_t N,index Line 525  index_t Finley_Util_cumsum(dim_t N,index
525            array[i]=tmp;            array[i]=tmp;
526          }          }
527        }        }
528          TMPMEMFREE(partial_sums);
529     #else     #else
530        for (i=0;i<N;++i) {        for (i=0;i<N;++i) {
531           tmp=out;           tmp=out;
# Line 488  index_t Finley_Util_cumsum(dim_t N,index Line 535  index_t Finley_Util_cumsum(dim_t N,index
535     #endif     #endif
536     return out;     return out;
537  }  }
538    void Dudley_Util_setValuesInUse(const index_t *values, const dim_t numValues, dim_t *numValuesInUse, index_t **valuesInUse, Paso_MPIInfo* mpiinfo)
539    {
540       dim_t i;
541       index_t lastFoundValue=INDEX_T_MIN, minFoundValue, local_minFoundValue, *newValuesInUse=NULL;
542       register index_t itmp;
543       bool_t allFound=FALSE;
544       dim_t nv=0;
545    
546       while (! allFound) {
547           /*
548            *  find smallest value bigger than lastFoundValue
549            */
550            minFoundValue=INDEX_T_MAX;
551            #pragma omp parallel private(local_minFoundValue)
552            {
553                local_minFoundValue=minFoundValue;
554                #pragma omp for private(i,itmp) schedule(static)
555                for (i=0;i< numValues;i++) {
556                   itmp=values[i];
557                   if ((itmp>lastFoundValue) && (itmp<local_minFoundValue)) local_minFoundValue=itmp;
558                }
559                #pragma omp critical
560                {
561                   if (local_minFoundValue<minFoundValue) minFoundValue=local_minFoundValue;
562                }
563    
564  void Finley_copyDouble(dim_t n,double* source, double* target) {           }
565    dim_t i;           #ifdef PASO_MPI
566    for (i=0;i<n;i++) target[i]=source[i];           local_minFoundValue=minFoundValue;
567             MPI_Allreduce(&local_minFoundValue,&minFoundValue, 1, MPI_INT, MPI_MIN, mpiinfo->comm );
568             #endif
569             /* if we found a new tag we need to add this too the valuesInUseList */
570    
571             if (minFoundValue < INDEX_T_MAX) {
572                 newValuesInUse=MEMALLOC(nv+1,index_t);
573                 if (*valuesInUse!=NULL) {
574                     memcpy(newValuesInUse,*valuesInUse,sizeof(index_t)*nv);
575                     MEMFREE(*valuesInUse);
576                 }
577                 newValuesInUse[nv]=minFoundValue;
578                 *valuesInUse=newValuesInUse;
579                 newValuesInUse=NULL;
580                 nv++;
581                 lastFoundValue=minFoundValue;
582             } else {
583                 allFound=TRUE;
584             }
585       }
586       *numValuesInUse=nv;
587  }  }
588    
589    
590  #ifdef PASO_MPI  #ifdef PASO_MPI
591  void Finley_printDoubleArray( FILE *fid, dim_t n, double *array, char *name  )  void Dudley_printDoubleArray( FILE *fid, dim_t n, double *array, char *name  )
592  {  {
593    index_t i;    index_t i;
594        
# Line 503  void Finley_printDoubleArray( FILE *fid, Line 596  void Finley_printDoubleArray( FILE *fid,
596      fprintf( fid, "%s [ ", name );      fprintf( fid, "%s [ ", name );
597    else    else
598      fprintf( fid, "[ " );        fprintf( fid, "[ " );  
599    for( i=0; i<(n<30 ? n : 30); i++ )    for( i=0; i<(n<60 ? n : 60); i++ )
600      fprintf( fid, "%g ", array[i] );      fprintf( fid, "%g ", array[i] );
601    if( n>=30 )    if( n>=30 )
602      fprintf( fid, "... " );      fprintf( fid, "... " );
603    fprintf( fid, "]\n" );    fprintf( fid, "]\n" );
604  }  }
605  void Finley_printIntArray( FILE *fid, dim_t n, int *array, char *name  )  void Dudley_printIntArray( FILE *fid, dim_t n, int *array, char *name  )
606  {  {
607    index_t i;    index_t i;
608        
# Line 517  void Finley_printIntArray( FILE *fid, di Line 610  void Finley_printIntArray( FILE *fid, di
610      fprintf( fid, "%s [ ", name );      fprintf( fid, "%s [ ", name );
611    else    else
612      fprintf( fid, "[ " );        fprintf( fid, "[ " );  
613    for( i=0; i<(n<30 ? n : 30); i++ )    for( i=0; i<(n<60 ? n : 60); i++ )
614      fprintf( fid, "%d ", array[i] );      fprintf( fid, "%d ", array[i] );
615    if( n>=30 )    if( n>=30 )
616      fprintf( fid, "... " );      fprintf( fid, "... " );
617    fprintf( fid, "]\n" );    fprintf( fid, "]\n" );
618  }  }
619  void Finley_printMaskArray( FILE *fid, dim_t n, int *array, char *name  )  void Dudley_printMaskArray( FILE *fid, dim_t n, int *array, char *name  )
620  {  {
621    index_t i;    index_t i;
622        
# Line 531  void Finley_printMaskArray( FILE *fid, d Line 624  void Finley_printMaskArray( FILE *fid, d
624      fprintf( fid, "%s [ ", name );      fprintf( fid, "%s [ ", name );
625    else    else
626      fprintf( fid, "[ " );        fprintf( fid, "[ " );  
627    for( i=0; i<(n<30 ? n : 30); i++ )    for( i=0; i<(n<60 ? n : 60); i++ )
628      if( array[i]!=-1 )      if( array[i]!=-1 )
629        fprintf( fid, "%d ", array[i] );        fprintf( fid, "%3d ", array[i] );
630      else      else
631        fprintf( fid, "* " );        fprintf( fid, "  * " );
632    if( n>=30 )    if( n>=30 )
633      fprintf( fid, "... " );      fprintf( fid, "... " );
634    fprintf( fid, "]\n" );    fprintf( fid, "]\n" );
635  }  }
636  #endif  #endif
   
 /*  
  * Revision 1.8  2005/08/12 01:45:43  jgs  
  *  
  * Revision 1.7.2.2  2005/09/07 06:26:22  gross  
  * the solver from finley are put into the standalone package paso now  
  *  
  * Revision 1.7.2.1  2005/08/04 22:41:11  gross  
  * some extra routines for finley that might speed-up RHS assembling in some cases (not actived right now)  
  *  
  * Revision 1.7  2005/07/08 04:07:59  jgs  
  * Merge of development branch back to main trunk on 2005-07-08  
  *  
  * Revision 1.1.1.1.2.4  2005/06/29 02:34:57  gross  
  * some changes towards 64 integers in finley  
  *  
  * Revision 1.1.1.1.2.3  2005/03/02 23:35:06  gross  
  * reimplementation of the ILU in Finley. block size>1 still needs some testing  
  *  
  * Revision 1.1.1.1.2.2  2005/02/18 02:27:31  gross  
  * two function that will be used for a reimplementation of the ILU preconditioner  
  *  
  * Revision 1.1.1.1.2.1  2004/11/12 06:58:19  gross  
  * a lot of changes to get the linearPDE class running: most important change is that there is no matrix format exposed to the user anymore. the format is chosen by the Domain according to the solver and symmetry  
  *  
  * Revision 1.1.1.1  2004/10/26 06:53:57  jgs  
  * initial import of project esys2  
  *  
  * Revision 1.3  2004/08/26 12:03:52  gross  
  * Some other bug in Finley_Assemble_gradient fixed.  
  *  
  * Revision 1.2  2004/07/02 04:21:13  gross  
  * Finley C code has been included  
  *  
  * Revision 1.1.1.1  2004/06/24 04:00:40  johng  
  * Initial version of eys using boost-python.  
  *  
  *  
  */  

Legend:
Removed from v.751  
changed lines
  Added in v.3086

  ViewVC Help
Powered by ViewVC 1.1.26