/[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 1388 by trankine, Fri Jan 11 07:45:58 2008 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  /**************************************************************/  /* $Id$ */
3    
4  /*   Some utility routines: */  /*******************************************************
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  /*   author: gross@access.edu.au */  /*   Some utility routines: */
 /*   Version: $Id$ */  
19    
20  /**************************************************************/  /**************************************************************/
21    
22  #include "Finley.h"  #include "Finley.h"
23  #include "Util.h"  #include "Util.h"
24    
25  #ifdef _OPENMP  #ifdef _OPENMP
26  #include <omp.h>  #include <omp.h>
27  #endif  #endif
# Line 71  void Finley_Util_Gather_int(dim_t len,in Line 70  void Finley_Util_Gather_int(dim_t len,in
70    
71  /*   adds a vector in into out using and index. */  /*   adds a vector in into out using and index. */
72    
73  /*        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}*/
74    
 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)];  
        }  
    }  
 }  
75    
76  #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){  
77     dim_t i,s;     dim_t i,s;
78     for (s=0;s<len;s++) {     for (s=0;s<len;s++) {
79         for(i=0;i<numData;i++) {         for(i=0;i<numData;i++) {
80            //#pragma omp atomic            if( index[s]<upperBound ) {
           if( index[s]<upperBound )  
81              out[INDEX2(i,index[s],numData)]+=in[INDEX2(i,s,numData)];              out[INDEX2(i,index[s],numData)]+=in[INDEX2(i,s,numData)];
82          }
83         }         }
84     }     }
85  }    }
   
   
 #endif  
86    
87  /*    multiplies two matrices */  /*    multiplies two matrices */
88    
# Line 371  int Finley_Util_ValueAndIndex_compar(con Line 353  int Finley_Util_ValueAndIndex_compar(con
353     e2=(Finley_Util_ValueAndIndex*) arg2;     e2=(Finley_Util_ValueAndIndex*) arg2;
354     if (e1->value < e2->value) return -1;     if (e1->value < e2->value) return -1;
355     if (e1->value > e2->value) return  1;     if (e1->value > e2->value) return  1;
356       if (e1->index < e2->index) return -1;
357       if (e1->index > e2->index) return  1;
358     return 0;     return 0;
359  }  }
360    
361  void Finley_Util_sortValueAndIndex(dim_t n,Finley_Util_ValueAndIndex* array) {  void Finley_Util_sortValueAndIndex(dim_t n,Finley_Util_ValueAndIndex* array) {
362       /* OMP : needs parallelization !*/       /* OMP : needs parallelization !*/
363       qsort(array,n,sizeof(Finley_Util_ValueAndIndex),Finley_Util_ValueAndIndex_compar);       qsort(array,n,sizeof(Finley_Util_ValueAndIndex),Finley_Util_ValueAndIndex_compar);
# Line 424  index_t Finley_Util_getMaxInt(dim_t dim, Line 409  index_t Finley_Util_getMaxInt(dim_t dim,
409     }     }
410     return out;     return out;
411  }  }
412    /**************************************************************/
413    
414    /* calculates the minimum value from a dim X N integer array */
415    
416    index_t Finley_Util_getFlaggedMinInt(dim_t dim,dim_t N,index_t* values, index_t ignore) {
417       dim_t i,j;
418       index_t out,out_local;
419       out=INDEX_T_MAX;
420       if (values!=NULL && dim*N>0 ) {
421         out=values[0];
422         #pragma omp parallel private(out_local)
423         {
424             out_local=out;
425             #pragma omp for private(i,j) schedule(static)
426             for (j=0;j<N;j++) {
427               for (i=0;i<dim;i++) if (values[INDEX2(i,j,dim)]!=ignore) out_local=MIN(out_local,values[INDEX2(i,j,dim)]);
428             }
429             #pragma omp critical
430             out=MIN(out_local,out);
431         }
432       }
433       return out;
434    }
435                                                                                                                                                      
436    /* calculates the maximum value from a dim X N integer array */
437    
438    index_t Finley_Util_getFlaggedMaxInt(dim_t dim,dim_t N,index_t* values, index_t ignore) {
439       dim_t i,j;
440       index_t out,out_local;
441       out=-INDEX_T_MAX;
442       if (values!=NULL && dim*N>0 ) {
443         out=values[0];
444         #pragma omp parallel private(out_local)
445         {
446             out_local=out;
447             #pragma omp for private(i,j) schedule(static)
448             for (j=0;j<N;j++) {
449                 for (i=0;i<dim;i++) if (values[INDEX2(i,j,dim)]!=ignore) out_local=MAX(out_local,values[INDEX2(i,j,dim)]);
450             }
451             #pragma omp critical
452             out=MAX(out_local,out);
453          }
454       }
455       return out;
456    }
457    
458  /* 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. */
459    
# Line 489  index_t Finley_Util_cumsum(dim_t N,index Line 519  index_t Finley_Util_cumsum(dim_t N,index
519     return out;     return out;
520  }  }
521    
 void Finley_copyDouble(dim_t n,double* source, double* target) {  
   dim_t i;  
   for (i=0;i<n;i++) target[i]=source[i];  
 }  
522    
523  #ifdef PASO_MPI  #ifdef PASO_MPI
524  void Finley_printDoubleArray( FILE *fid, dim_t n, double *array, char *name  )  void Finley_printDoubleArray( FILE *fid, dim_t n, double *array, char *name  )
# Line 503  void Finley_printDoubleArray( FILE *fid, Line 529  void Finley_printDoubleArray( FILE *fid,
529      fprintf( fid, "%s [ ", name );      fprintf( fid, "%s [ ", name );
530    else    else
531      fprintf( fid, "[ " );        fprintf( fid, "[ " );  
532    for( i=0; i<(n<30 ? n : 30); i++ )    for( i=0; i<(n<60 ? n : 60); i++ )
533      fprintf( fid, "%g ", array[i] );      fprintf( fid, "%g ", array[i] );
534    if( n>=30 )    if( n>=30 )
535      fprintf( fid, "... " );      fprintf( fid, "... " );
# Line 517  void Finley_printIntArray( FILE *fid, di Line 543  void Finley_printIntArray( FILE *fid, di
543      fprintf( fid, "%s [ ", name );      fprintf( fid, "%s [ ", name );
544    else    else
545      fprintf( fid, "[ " );        fprintf( fid, "[ " );  
546    for( i=0; i<(n<30 ? n : 30); i++ )    for( i=0; i<(n<60 ? n : 60); i++ )
547      fprintf( fid, "%d ", array[i] );      fprintf( fid, "%d ", array[i] );
548    if( n>=30 )    if( n>=30 )
549      fprintf( fid, "... " );      fprintf( fid, "... " );
# Line 531  void Finley_printMaskArray( FILE *fid, d Line 557  void Finley_printMaskArray( FILE *fid, d
557      fprintf( fid, "%s [ ", name );      fprintf( fid, "%s [ ", name );
558    else    else
559      fprintf( fid, "[ " );        fprintf( fid, "[ " );  
560    for( i=0; i<(n<30 ? n : 30); i++ )    for( i=0; i<(n<60 ? n : 60); i++ )
561      if( array[i]!=-1 )      if( array[i]!=-1 )
562        fprintf( fid, "%d ", array[i] );        fprintf( fid, "%3d ", array[i] );
563      else      else
564        fprintf( fid, "* " );        fprintf( fid, "  * " );
565    if( n>=30 )    if( n>=30 )
566      fprintf( fid, "... " );      fprintf( fid, "... " );
567    fprintf( fid, "]\n" );    fprintf( fid, "]\n" );
568  }  }
569  #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.1388

  ViewVC Help
Powered by ViewVC 1.1.26