/[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 471 by jgs, Fri Jan 27 01:33:02 2006 UTC temp_trunk_copy/finley/src/Util.c revision 1384 by phornby, Fri Jan 11 02:29:38 2008 UTC
# Line 1  Line 1 
 /*  
  ******************************************************************************  
  *                                                                            *  
  *       COPYRIGHT  ACcESS 2003,2004,2005 -  All Rights Reserved              *  
  *                                                                            *  
  * This software is the property of ACcESS. No part of this code              *  
  * may be copied in any form or by any means without the expressed written    *  
  * consent of ACcESS.  Copying, use or modification of this software          *  
  * by any unauthorised person is illegal unless that person has a software    *  
  * license agreement with ACcESS.                                             *  
  *                                                                            *  
  ******************************************************************************  
 */  
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 73  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    
75  void Finley_Util_AddScatter(dim_t len,index_t* index,dim_t numData,double* in,double * out){  
76    void Finley_Util_AddScatter(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 ) {
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  }  }
# Line 354  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 407  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 472  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
524   * Revision 1.8  2005/08/12 01:45:43  jgs  void Finley_printDoubleArray( FILE *fid, dim_t n, double *array, char *name  )
525   * erge of development branch dev-02 back to main trunk on 2005-08-12  {
526   *    index_t i;
527   * Revision 1.7.2.2  2005/09/07 06:26:22  gross    
528   * the solver from finley are put into the standalone package paso now    if( name )
529   *      fprintf( fid, "%s [ ", name );
530   * Revision 1.7.2.1  2005/08/04 22:41:11  gross    else
531   * some extra routines for finley that might speed-up RHS assembling in some cases (not actived right now)      fprintf( fid, "[ " );  
532   *    for( i=0; i<(n<60 ? n : 60); i++ )
533   * Revision 1.7  2005/07/08 04:07:59  jgs      fprintf( fid, "%g ", array[i] );
534   * Merge of development branch back to main trunk on 2005-07-08    if( n>=30 )
535   *      fprintf( fid, "... " );
536   * Revision 1.1.1.1.2.4  2005/06/29 02:34:57  gross    fprintf( fid, "]\n" );
537   * some changes towards 64 integers in finley  }
538   *  void Finley_printIntArray( FILE *fid, dim_t n, int *array, char *name  )
539   * Revision 1.1.1.1.2.3  2005/03/02 23:35:06  gross  {
540   * reimplementation of the ILU in Finley. block size>1 still needs some testing    index_t i;
541   *    
542   * Revision 1.1.1.1.2.2  2005/02/18 02:27:31  gross    if( name )
543   * two function that will be used for a reimplementation of the ILU preconditioner      fprintf( fid, "%s [ ", name );
544   *    else
545   * Revision 1.1.1.1.2.1  2004/11/12 06:58:19  gross      fprintf( fid, "[ " );  
546   * 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    for( i=0; i<(n<60 ? n : 60); i++ )
547   *      fprintf( fid, "%d ", array[i] );
548   * Revision 1.1.1.1  2004/10/26 06:53:57  jgs    if( n>=30 )
549   * initial import of project esys2      fprintf( fid, "... " );
550   *    fprintf( fid, "]\n" );
551   * Revision 1.3  2004/08/26 12:03:52  gross  }
552   * Some other bug in Finley_Assemble_gradient fixed.  void Finley_printMaskArray( FILE *fid, dim_t n, int *array, char *name  )
553   *  {
554   * Revision 1.2  2004/07/02 04:21:13  gross    index_t i;
555   * Finley C code has been included    
556   *    if( name )
557   * Revision 1.1.1.1  2004/06/24 04:00:40  johng      fprintf( fid, "%s [ ", name );
558   * Initial version of eys using boost-python.    else
559   *      fprintf( fid, "[ " );  
560   *    for( i=0; i<(n<60 ? n : 60); i++ )
561   */      if( array[i]!=-1 )
562          fprintf( fid, "%3d ", array[i] );
563        else
564          fprintf( fid, "  * " );
565      if( n>=30 )
566        fprintf( fid, "... " );
567      fprintf( fid, "]\n" );
568    }
569    #endif

Legend:
Removed from v.471  
changed lines
  Added in v.1384

  ViewVC Help
Powered by ViewVC 1.1.26