/[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

revision 751 by bcumming, Mon Jun 26 01:46:34 2006 UTC revision 799 by ksteube, Mon Aug 7 23:30:53 2006 UTC
# Line 23  Line 23 
23    
24  #include "Finley.h"  #include "Finley.h"
25  #include "Util.h"  #include "Util.h"
26    
27  #ifdef _OPENMP  #ifdef _OPENMP
28  #include <omp.h>  #include <omp.h>
29  #endif  #endif
# Line 71  void Finley_Util_Gather_int(dim_t len,in Line 72  void Finley_Util_Gather_int(dim_t len,in
72    
73  /*   adds a vector in into out using and index. */  /*   adds a vector in into out using and index. */
74    
75  /*        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}*/
76    
 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)];  
        }  
    }  
 }  
77    
78  #ifdef PASO_MPI  void Finley_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){  
79     dim_t i,s;     dim_t i,s;
80     for (s=0;s<len;s++) {     for (s=0;s<len;s++) {
81         for(i=0;i<numData;i++) {         for(i=0;i<numData;i++) {
82            //#pragma omp atomic            if( index[s]<upperBound ) {
83            if( index[s]<upperBound )              #pragma omp atomic
84              out[INDEX2(i,index[s],numData)]+=in[INDEX2(i,s,numData)];              out[INDEX2(i,index[s],numData)]+=in[INDEX2(i,s,numData)];
85          }
86         }         }
87     }     }
88  }    }
   
   
 #endif  
89    
90  /*    multiplies two matrices */  /*    multiplies two matrices */
91    
# Line 371  int Finley_Util_ValueAndIndex_compar(con Line 356  int Finley_Util_ValueAndIndex_compar(con
356     e2=(Finley_Util_ValueAndIndex*) arg2;     e2=(Finley_Util_ValueAndIndex*) arg2;
357     if (e1->value < e2->value) return -1;     if (e1->value < e2->value) return -1;
358     if (e1->value > e2->value) return  1;     if (e1->value > e2->value) return  1;
359       if (e1->index < e2->index) return -1;
360       if (e1->index > e2->index) return  1;
361    
362     return 0;     return 0;
363  }  }
364    
365  void Finley_Util_sortValueAndIndex(dim_t n,Finley_Util_ValueAndIndex* array) {  void Finley_Util_sortValueAndIndex(dim_t n,Finley_Util_ValueAndIndex* array) {
366       /* OMP : needs parallelization !*/       /* OMP : needs parallelization !*/
367       qsort(array,n,sizeof(Finley_Util_ValueAndIndex),Finley_Util_ValueAndIndex_compar);       qsort(array,n,sizeof(Finley_Util_ValueAndIndex),Finley_Util_ValueAndIndex_compar);
# Line 503  void Finley_printDoubleArray( FILE *fid, Line 492  void Finley_printDoubleArray( FILE *fid,
492      fprintf( fid, "%s [ ", name );      fprintf( fid, "%s [ ", name );
493    else    else
494      fprintf( fid, "[ " );        fprintf( fid, "[ " );  
495    for( i=0; i<(n<30 ? n : 30); i++ )    for( i=0; i<(n<60 ? n : 60); i++ )
496      fprintf( fid, "%g ", array[i] );      fprintf( fid, "%g ", array[i] );
497    if( n>=30 )    if( n>=30 )
498      fprintf( fid, "... " );      fprintf( fid, "... " );
# Line 517  void Finley_printIntArray( FILE *fid, di Line 506  void Finley_printIntArray( FILE *fid, di
506      fprintf( fid, "%s [ ", name );      fprintf( fid, "%s [ ", name );
507    else    else
508      fprintf( fid, "[ " );        fprintf( fid, "[ " );  
509    for( i=0; i<(n<30 ? n : 30); i++ )    for( i=0; i<(n<60 ? n : 60); i++ )
510      fprintf( fid, "%d ", array[i] );      fprintf( fid, "%d ", array[i] );
511    if( n>=30 )    if( n>=30 )
512      fprintf( fid, "... " );      fprintf( fid, "... " );
# Line 531  void Finley_printMaskArray( FILE *fid, d Line 520  void Finley_printMaskArray( FILE *fid, d
520      fprintf( fid, "%s [ ", name );      fprintf( fid, "%s [ ", name );
521    else    else
522      fprintf( fid, "[ " );        fprintf( fid, "[ " );  
523    for( i=0; i<(n<30 ? n : 30); i++ )    for( i=0; i<(n<60 ? n : 60); i++ )
524      if( array[i]!=-1 )      if( array[i]!=-1 )
525        fprintf( fid, "%d ", array[i] );        fprintf( fid, "%3d ", array[i] );
526      else      else
527        fprintf( fid, "* " );        fprintf( fid, "  * " );
528    if( n>=30 )    if( n>=30 )
529      fprintf( fid, "... " );      fprintf( fid, "... " );
530    fprintf( fid, "]\n" );    fprintf( fid, "]\n" );

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

  ViewVC Help
Powered by ViewVC 1.1.26