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

revision 765 by gross, Fri Jun 30 06:37:11 2006 UTC revision 2425 by gross, Thu May 14 09:06:35 2009 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-2008 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
# Line 72  void Finley_Util_Gather_int(dim_t len,in Line 69  void Finley_Util_Gather_int(dim_t len,in
69
70  /*   adds a vector in into out using and index. */  /*   adds a vector in into out using and index. */
71
72  /*        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}*/
73
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)];
}
}
}
74
75  #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){
76     dim_t i,s;     dim_t i,s;
77     for (s=0;s<len;s++) {     for (s=0;s<len;s++) {
78         for(i=0;i<numData;i++) {         for(i=0;i<numData;i++) {
79            //#pragma omp atomic            if( index[s]<upperBound ) {
if( index[s]<upperBound )
80              out[INDEX2(i,index[s],numData)]+=in[INDEX2(i,s,numData)];              out[INDEX2(i,index[s],numData)]+=in[INDEX2(i,s,numData)];
81          }
82         }         }
83     }     }
84  }    }

#endif
85
86  /*    multiplies two matrices */  /*    multiplies two matrices */
87
# Line 374  int Finley_Util_ValueAndIndex_compar(con Line 354  int Finley_Util_ValueAndIndex_compar(con
354     if (e1->value > e2->value) return  1;     if (e1->value > e2->value) return  1;
355     if (e1->index < e2->index) return -1;     if (e1->index < e2->index) return -1;
356     if (e1->index > e2->index) return  1;     if (e1->index > e2->index) return  1;

357     return 0;     return 0;
358  }  }
359
# Line 429  index_t Finley_Util_getMaxInt(dim_t dim, Line 408  index_t Finley_Util_getMaxInt(dim_t dim,
408     }     }
409     return out;     return out;
410  }  }
411    /**************************************************************/
412
413    /* calculates the minimum value from a dim X N integer array */
414
415    index_t Finley_Util_getFlaggedMinInt(dim_t dim,dim_t N,index_t* values, index_t ignore) {
416       dim_t i,j;
417       index_t out,out_local;
418       out=INDEX_T_MAX;
419       if (values!=NULL && dim*N>0 ) {
420         out=values[0];
421         #pragma omp parallel private(out_local)
422         {
423             out_local=out;
424             #pragma omp for private(i,j) schedule(static)
425             for (j=0;j<N;j++) {
426               for (i=0;i<dim;i++) if (values[INDEX2(i,j,dim)]!=ignore) out_local=MIN(out_local,values[INDEX2(i,j,dim)]);
427             }
428             #pragma omp critical
429             out=MIN(out_local,out);
430         }
431       }
432       return out;
433    }
434
435    /* calculates the maximum value from a dim X N integer array */
436
437    index_t Finley_Util_getFlaggedMaxInt(dim_t dim,dim_t N,index_t* values, index_t ignore) {
438       dim_t i,j;
439       index_t out,out_local;
440       out=-INDEX_T_MAX;
441       if (values!=NULL && dim*N>0 ) {
442         out=values[0];
443         #pragma omp parallel private(out_local)
444         {
445             out_local=out;
446             #pragma omp for private(i,j) schedule(static)
447             for (j=0;j<N;j++) {
448                 for (i=0;i<dim;i++) if (values[INDEX2(i,j,dim)]!=ignore) out_local=MAX(out_local,values[INDEX2(i,j,dim)]);
449             }
450             #pragma omp critical
451             out=MAX(out_local,out);
452          }
453       }
454       return out;
455    }
456
457  /* 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. */
458
# Line 458  index_t Finley_Util_cumsum(dim_t N,index Line 482  index_t Finley_Util_cumsum(dim_t N,index
482     index_t out=0,tmp;     index_t out=0,tmp;
483     dim_t i;     dim_t i;
484     #ifdef _OPENMP     #ifdef _OPENMP
485        index_t partial_sums[omp_get_max_threads()],sum;        index_t *partial_sums=NULL, sum;
486          partial_sums=TMPMEMALLOC(omp_get_max_threads(),index_t);
487        #pragma omp parallel private(sum,i,tmp)        #pragma omp parallel private(sum,i,tmp)
488        {        {
489          sum=0;          sum=0;
# Line 484  index_t Finley_Util_cumsum(dim_t N,index Line 509  index_t Finley_Util_cumsum(dim_t N,index
509            array[i]=tmp;            array[i]=tmp;
510          }          }
511        }        }
512          TMPMEMFREE(partial_sums);
513     #else     #else
514        for (i=0;i<N;++i) {        for (i=0;i<N;++i) {
515           tmp=out;           tmp=out;
# Line 493  index_t Finley_Util_cumsum(dim_t N,index Line 519  index_t Finley_Util_cumsum(dim_t N,index
519     #endif     #endif
520     return out;     return out;
521  }  }
522    void Finley_Util_setValuesInUse(const index_t *values, const dim_t numValues, dim_t *numValuesInUse, index_t **valuesInUse, Paso_MPIInfo* mpiinfo)
523    {
524       dim_t i;
525       index_t lastFoundValue=INDEX_T_MIN, minFoundValue, local_minFoundValue, *newValuesInUse=NULL;
526       register index_t itmp;
527       bool_t allFound=FALSE;
528       dim_t nv=0;
529
530       while (! allFound) {
531           /*
532            *  find smallest value bigger than lastFoundValue
533            */
534            minFoundValue=INDEX_T_MAX;
535            #pragma omp parallel private(local_minFoundValue)
536            {
537                local_minFoundValue=minFoundValue;
538                #pragma omp for private(i,itmp) schedule(static)
539                for (i=0;i< numValues;i++) {
540                   itmp=values[i];
541                   if ((itmp>lastFoundValue) && (itmp<local_minFoundValue)) local_minFoundValue=itmp;
542                }
543                #pragma omp critical
544                {
545                   if (local_minFoundValue<minFoundValue) minFoundValue=local_minFoundValue;
546                }
547
548  void Finley_copyDouble(dim_t n,double* source, double* target) {           }
549    dim_t i;           #ifdef PASO_MPI
550    for (i=0;i<n;i++) target[i]=source[i];           local_minFoundValue=minFoundValue;
551             MPI_Allreduce(&local_minFoundValue,&minFoundValue, 1, MPI_INT, MPI_MIN, mpiinfo->comm );
552             #endif
553             /* if we found a new tag we need to add this too the valuesInUseList */
554
555             if (minFoundValue < INDEX_T_MAX) {
556                 newValuesInUse=MEMALLOC(nv+1,index_t);
557                 if (*valuesInUse!=NULL) {
558                     memcpy(newValuesInUse,*valuesInUse,sizeof(index_t)*nv);
559                     MEMFREE(*valuesInUse);
560                 }
561                 newValuesInUse[nv]=minFoundValue;
562                 *valuesInUse=newValuesInUse;
563                 newValuesInUse=NULL;
564                 nv++;
565                 lastFoundValue=minFoundValue;
566             } else {
567                 allFound=TRUE;
568             }
569       }
570       *numValuesInUse=nv;
571  }  }
572
573
574  #ifdef PASO_MPI  #ifdef PASO_MPI
575  void Finley_printDoubleArray( FILE *fid, dim_t n, double *array, char *name  )  void Finley_printDoubleArray( FILE *fid, dim_t n, double *array, char *name  )
576  {  {
# Line 508  void Finley_printDoubleArray( FILE *fid, Line 580  void Finley_printDoubleArray( FILE *fid,
580      fprintf( fid, "%s [ ", name );      fprintf( fid, "%s [ ", name );
581    else    else
582      fprintf( fid, "[ " );        fprintf( fid, "[ " );
583    for( i=0; i<(n<30 ? n : 30); i++ )    for( i=0; i<(n<60 ? n : 60); i++ )
584      fprintf( fid, "%g ", array[i] );      fprintf( fid, "%g ", array[i] );
585    if( n>=30 )    if( n>=30 )
586      fprintf( fid, "... " );      fprintf( fid, "... " );
# Line 522  void Finley_printIntArray( FILE *fid, di Line 594  void Finley_printIntArray( FILE *fid, di
594      fprintf( fid, "%s [ ", name );      fprintf( fid, "%s [ ", name );
595    else    else
596      fprintf( fid, "[ " );        fprintf( fid, "[ " );
597    for( i=0; i<(n<30 ? n : 30); i++ )    for( i=0; i<(n<60 ? n : 60); i++ )
598      fprintf( fid, "%d ", array[i] );      fprintf( fid, "%d ", array[i] );
599    if( n>=30 )    if( n>=30 )
600      fprintf( fid, "... " );      fprintf( fid, "... " );
# Line 536  void Finley_printMaskArray( FILE *fid, d Line 608  void Finley_printMaskArray( FILE *fid, d
608      fprintf( fid, "%s [ ", name );      fprintf( fid, "%s [ ", name );
609    else    else
610      fprintf( fid, "[ " );        fprintf( fid, "[ " );
611    for( i=0; i<(n<30 ? n : 30); i++ )    for( i=0; i<(n<60 ? n : 60); i++ )
612      if( array[i]!=-1 )      if( array[i]!=-1 )
613        fprintf( fid, "%d ", array[i] );        fprintf( fid, "%3d ", array[i] );
614      else      else
615        fprintf( fid, "* " );        fprintf( fid, "  * " );
616    if( n>=30 )    if( n>=30 )
617      fprintf( fid, "... " );      fprintf( fid, "... " );
618    fprintf( fid, "]\n" );    fprintf( fid, "]\n" );
619  }  }
620  #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.765 changed lines Added in v.2425

 ViewVC Help Powered by ViewVC 1.1.26