--- trunk/esys2/finley/src/finleyC/Util.c 2005/08/12 01:45:47 147 +++ trunk/finley/src/Util.c 2008/09/25 23:11:13 1811 @@ -1,20 +1,26 @@ -/* \$Id\$ */ -/**************************************************************/ +/******************************************************* +* +* Copyright (c) 2003-2008 by University of Queensland +* Earth Systems Science Computational Center (ESSCC) +* http://www.uq.edu.au/esscc +* +* Primary Business: Queensland, Australia +* Licensed under the Open Software License version 3.0 +* http://www.opensource.org/licenses/osl-3.0.php +* +*******************************************************/ -/* Some utility routines: */ /**************************************************************/ -/* Copyrights by ACcESS Australia, 2003 */ -/* author: gross@access.edu.au */ -/* Version: \$Id\$ */ +/* Some utility routines: */ /**************************************************************/ -#include "Common.h" #include "Finley.h" #include "Util.h" + #ifdef _OPENMP #include #endif @@ -63,14 +69,16 @@ /* adds a vector in into out using and index. */ -/* 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]0) { - Finley_ErrorCode=ZERO_DIVISION_ERROR; - sprintf(Finley_ErrorMsg,"area equals zero."); + Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: area equals zero."); return; } else { invlength=1./length; @@ -274,8 +278,7 @@ CO_A33=A11*A22-A21*A12; length=sqrt(CO_A13*CO_A13+CO_A23*CO_A23+CO_A33*CO_A33); if (! length>0) { - Finley_ErrorCode=ZERO_DIVISION_ERROR; - sprintf(Finley_ErrorMsg,"area equals zero."); + Finley_setError(ZERO_DIVISION_ERROR,"__FILE__: area equals zero."); return; } else { invlength=1./length; @@ -349,8 +352,11 @@ e2=(Finley_Util_ValueAndIndex*) arg2; if (e1->value < e2->value) return -1; if (e1->value > e2->value) return 1; + if (e1->index < e2->index) return -1; + if (e1->index > e2->index) return 1; return 0; } + void Finley_Util_sortValueAndIndex(dim_t n,Finley_Util_ValueAndIndex* array) { /* OMP : needs parallelization !*/ qsort(array,n,sizeof(Finley_Util_ValueAndIndex),Finley_Util_ValueAndIndex_compar); @@ -402,6 +408,51 @@ } return out; } +/**************************************************************/ + +/* calculates the minimum value from a dim X N integer array */ + +index_t Finley_Util_getFlaggedMinInt(dim_t dim,dim_t N,index_t* values, index_t ignore) { + dim_t i,j; + index_t out,out_local; + out=INDEX_T_MAX; + if (values!=NULL && dim*N>0 ) { + out=values[0]; + #pragma omp parallel private(out_local) + { + out_local=out; + #pragma omp for private(i,j) schedule(static) + for (j=0;j0 ) { + out=values[0]; + #pragma omp parallel private(out_local) + { + out_local=out; + #pragma omp for private(i,j) schedule(static) + for (j=0;jlastFoundValue) && (itmpcomm ); + #endif + + /* if we found a new tag we need to add this too the valuesInUseList */ + + if (minFoundValue < INDEX_T_MAX) { + newValuesInUse=MEMALLOC(nv+1,index_t); + if (*valuesInUse!=NULL) { + memcpy(newValuesInUse,*valuesInUse,sizeof(index_t)*nv); + MEMFREE(*valuesInUse); + } + newValuesInUse[nv]=minFoundValue; + *valuesInUse=newValuesInUse; + newValuesInUse=NULL; + nv++; + lastFoundValue=minFoundValue; + } else { + allFound=TRUE; + } + } + *numValuesInUse=nv; +} -void Finley_copyDouble(dim_t n,double* source, double* target) { - dim_t i; - for (i=0;i1 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. - * - * - */ + +#ifdef PASO_MPI +void Finley_printDoubleArray( FILE *fid, dim_t n, double *array, char *name ) +{ + index_t i; + + if( name ) + fprintf( fid, "%s [ ", name ); + else + fprintf( fid, "[ " ); + for( i=0; i<(n<60 ? n : 60); i++ ) + fprintf( fid, "%g ", array[i] ); + if( n>=30 ) + fprintf( fid, "... " ); + fprintf( fid, "]\n" ); +} +void Finley_printIntArray( FILE *fid, dim_t n, int *array, char *name ) +{ + index_t i; + + if( name ) + fprintf( fid, "%s [ ", name ); + else + fprintf( fid, "[ " ); + for( i=0; i<(n<60 ? n : 60); i++ ) + fprintf( fid, "%d ", array[i] ); + if( n>=30 ) + fprintf( fid, "... " ); + fprintf( fid, "]\n" ); +} +void Finley_printMaskArray( FILE *fid, dim_t n, int *array, char *name ) +{ + index_t i; + + if( name ) + fprintf( fid, "%s [ ", name ); + else + fprintf( fid, "[ " ); + for( i=0; i<(n<60 ? n : 60); i++ ) + if( array[i]!=-1 ) + fprintf( fid, "%3d ", array[i] ); + else + fprintf( fid, " * " ); + if( n>=30 ) + fprintf( fid, "... " ); + fprintf( fid, "]\n" ); +} +#endif