/[escript]/trunk/finley/src/Util.c
ViewVC logotype

Diff of /trunk/finley/src/Util.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 115 by jgs, Fri Mar 4 07:12:47 2005 UTC revision 123 by jgs, Fri Jul 8 04:08:13 2005 UTC
# Line 25  Line 25 
25    
26  /*        out(1:numData,1:len)=in(1:numData,index(1:len)) */  /*        out(1:numData,1:len)=in(1:numData,index(1:len)) */
27    
28  void Finley_Util_Gather_double(int len,maybelong* index,int numData,double* in, double * out){  void Finley_Util_Gather_double(dim_t len,index_t* index,dim_t numData,double* in, double * out){
29      int s,i;      dim_t s,i;
30      for (s=0;s<len;s++) {      for (s=0;s<len;s++) {
31         for (i=0;i<numData;i++) {         for (i=0;i<numData;i++) {
32            out[INDEX2(i,s,numData)]=in[INDEX2(i,index[s],numData)];            out[INDEX2(i,s,numData)]=in[INDEX2(i,index[s],numData)];
# Line 41  void Finley_Util_Gather_double(int len,m Line 41  void Finley_Util_Gather_double(int len,m
41    
42  /*        out(1:numData,1:len)=in(1:numData,index(1:len)) */  /*        out(1:numData,1:len)=in(1:numData,index(1:len)) */
43    
44  void Finley_Util_Gather_int(int len,maybelong* index,int numData, maybelong* in, maybelong * out){  void Finley_Util_Gather_int(dim_t len,index_t* index,dim_t numData, index_t* in, index_t * out){
45      int s,i;      dim_t s,i;
46      for (s=0;s<len;s++) {      for (s=0;s<len;s++) {
47         for (i=0;i<numData;i++) {         for (i=0;i<numData;i++) {
48            out[INDEX2(i,s,numData)]=in[INDEX2(i,index[s],numData)];            out[INDEX2(i,s,numData)]=in[INDEX2(i,index[s],numData)];
# Line 56  void Finley_Util_Gather_int(int len,mayb Line 56  void Finley_Util_Gather_int(int len,mayb
56    
57  /*        out(1:numData,index(1:len))+=in(1:numData,1:len) */  /*        out(1:numData,index(1:len))+=in(1:numData,1:len) */
58    
59  void Finley_Util_AddScatter(int len,maybelong* index,int numData,double* in,double * out){  void Finley_Util_AddScatter(dim_t len,index_t* index,dim_t numData,double* in,double * out){
60     int i,s;     dim_t i,s;
61     for (s=0;s<len;s++) {     for (s=0;s<len;s++) {
62         for(i=0;i<numData;i++) {         for(i=0;i<numData;i++) {
63            #pragma omp atomic            #pragma omp atomic
# Line 70  void Finley_Util_AddScatter(int len,mayb Line 70  void Finley_Util_AddScatter(int len,mayb
70    
71  /*          A(1:A1,1:A2)=B(1:A1,1:B2)*C(1:B2,1:A2) */  /*          A(1:A1,1:A2)=B(1:A1,1:B2)*C(1:B2,1:A2) */
72    
73  void Finley_Util_SmallMatMult(int A1,int A2, double* A, int B2, double*B, double* C) {  void Finley_Util_SmallMatMult(dim_t A1,dim_t A2, double* A, dim_t B2, double*B, double* C) {
74      int i,j,s;      dim_t i,j,s;
75      for (i=0;i<A1*A2;i++) A[i]=0;      for (i=0;i<A1*A2;i++) A[i]=0;
76         for (i=0;i<A1;i++) {         for (i=0;i<A1;i++) {
77            for (j=0;j<A2;j++) {            for (j=0;j<A2;j++) {
# Line 86  void Finley_Util_SmallMatMult(int A1,int Line 86  void Finley_Util_SmallMatMult(int A1,int
86    
87  /*        A(1:A1,1:A2,i)=B(1:A1,1:B2,i)*C(1:B2,1:A2,i) i=1,len */  /*        A(1:A1,1:A2,i)=B(1:A1,1:B2,i)*C(1:B2,1:A2,i) i=1,len */
88    
89  void Finley_Util_SmallMatSetMult(int len,int A1,int A2, double* A, int B2, double*B, double* C) {  void Finley_Util_SmallMatSetMult(dim_t len,dim_t A1,dim_t A2, double* A, dim_t B2, double*B, double* C) {
90      int q,i,j,s;      dim_t q,i,j,s;
91      for (i=0;i<A1*A2*len;i++) A[i]=0;      for (i=0;i<A1*A2*len;i++) A[i]=0;
92      for (q=0;q<len;q++) {      for (q=0;q<len;q++) {
93         for (i=0;i<A1;i++) {         for (i=0;i<A1;i++) {
# Line 102  void Finley_Util_SmallMatSetMult(int len Line 102  void Finley_Util_SmallMatSetMult(int len
102  /*    inverts the set of dim x dim matrices A(:,:,1:len) with dim=1,2,3 */  /*    inverts the set of dim x dim matrices A(:,:,1:len) with dim=1,2,3 */
103  /*    the determinante is returned. */  /*    the determinante is returned. */
104    
105  void Finley_Util_InvertSmallMat(int len,int dim,double* A,double *invA, double* det){  void Finley_Util_InvertSmallMat(dim_t len,dim_t dim,double* A,double *invA, double* det){
106     int q;     dim_t q;
107     double D,A11,A12,A13,A21,A22,A23,A31,A32,A33;     register double D,A11,A12,A13,A21,A22,A23,A31,A32,A33;
108    
109     switch(dim) {     switch(dim) {
110        case 1:        case 1:
# Line 184  void Finley_Util_InvertSmallMat(int len, Line 184  void Finley_Util_InvertSmallMat(int len,
184    
185  /*    sets the derterminate of a set of dim x dim matrices A(:,:,1:len) with dim=1,2,3 */  /*    sets the derterminate of a set of dim x dim matrices A(:,:,1:len) with dim=1,2,3 */
186    
187  void Finley_Util_DetOfSmallMat(int len,int dim,double* A, double* det){  void Finley_Util_DetOfSmallMat(dim_t len,dim_t dim,double* A, double* det){
188     int q;     dim_t q;
189     double A11,A12,A13,A21,A22,A23,A31,A32,A33;     register double A11,A12,A13,A21,A22,A23,A31,A32,A33;
190    
191     switch(dim) {     switch(dim) {
192        case 1:        case 1:
# Line 228  void Finley_Util_DetOfSmallMat(int len,i Line 228  void Finley_Util_DetOfSmallMat(int len,i
228  /*    returns the normalized vector Normal[dim,len] orthogonal to A(:,0,q) and A(:,1,q) in the case of dim=3  */  /*    returns the normalized vector Normal[dim,len] orthogonal to A(:,0,q) and A(:,1,q) in the case of dim=3  */
229  /*    or the vector A(:,0,q) in the case of dim=2                                             */  /*    or the vector A(:,0,q) in the case of dim=2                                             */
230    
231  void  Finley_NormalVector(int len, int dim, int dim1, double* A,double* Normal) {  void  Finley_NormalVector(dim_t len, dim_t dim, dim_t dim1, double* A,double* Normal) {
232     int q;     dim_t q;
233     double A11,A12,CO_A13,A21,A22,CO_A23,A31,A32,CO_A33,length,invlength;     register double A11,A12,CO_A13,A21,A22,CO_A23,A31,A32,CO_A33,length,invlength;
234    
235     switch(dim) {     switch(dim) {
236        case 1:        case 1:
# Line 285  void  Finley_NormalVector(int len, int d Line 285  void  Finley_NormalVector(int len, int d
285  /*    return the length of the vector which is orthogonal to the vectors A(:,0,q) and A(:,1,q) in the case of dim=3 */  /*    return the length of the vector which is orthogonal to the vectors A(:,0,q) and A(:,1,q) in the case of dim=3 */
286  /*    or the vector A(:,0,q) in the case of dim=2                                                                   */  /*    or the vector A(:,0,q) in the case of dim=2                                                                   */
287    
288  void  Finley_LengthOfNormalVector(int len, int dim, int dim1, double* A,double* length) {  void  Finley_LengthOfNormalVector(dim_t len, dim_t dim, dim_t dim1, double* A,double* length) {
289     int q;     dim_t q;
290     double A11,A12,CO_A13,A21,A22,CO_A23,A31,A32,CO_A33;     double A11,A12,CO_A13,A21,A22,CO_A23,A31,A32,CO_A33;
291    
292     switch(dim) {     switch(dim) {
# Line 323  void  Finley_LengthOfNormalVector(int le Line 323  void  Finley_LengthOfNormalVector(int le
323  /* there is no range checking! */  /* there is no range checking! */
324  /* at output Map[invMap[i]]=i for i=0:lenInvMap */  /* at output Map[invMap[i]]=i for i=0:lenInvMap */
325    
326  void Finley_Util_InvertMap(int lenInvMap, maybelong* invMap,int lenMap, maybelong* Map) {  void Finley_Util_InvertMap(dim_t lenInvMap, index_t* invMap,dim_t lenMap, index_t* Map) {
327     int i;     dim_t i;
328     for (i=0;i<lenInvMap;i++) invMap[i]=0;     for (i=0;i<lenInvMap;i++) invMap[i]=0;
329     for (i=0;i<lenMap;i++) {     for (i=0;i<lenMap;i++) {
330        if (Map[i]>=0) invMap[Map[i]]=i;        if (Map[i]>=0) invMap[Map[i]]=i;
# Line 342  int Finley_Util_ValueAndIndex_compar(con Line 342  int Finley_Util_ValueAndIndex_compar(con
342     if (e1->value > e2->value) return  1;     if (e1->value > e2->value) return  1;
343     return 0;     return 0;
344  }  }
345  void Finley_Util_sortValueAndIndex(int n,Finley_Util_ValueAndIndex* array) {  void Finley_Util_sortValueAndIndex(dim_t n,Finley_Util_ValueAndIndex* array) {
346       /* OMP : needs parallelization !*/       /* OMP : needs parallelization !*/
347       qsort(array,n,sizeof(Finley_Util_ValueAndIndex),Finley_Util_ValueAndIndex_compar);       qsort(array,n,sizeof(Finley_Util_ValueAndIndex),Finley_Util_ValueAndIndex_compar);
348  }  }
# Line 352  void Finley_Util_sortValueAndIndex(int n Line 352  void Finley_Util_sortValueAndIndex(int n
352    
353  /* calculates the minimum value from a dim X N integer array */  /* calculates the minimum value from a dim X N integer array */
354    
355  maybelong Finley_Util_getMinInt(int dim,int N,maybelong* values) {  index_t Finley_Util_getMinInt(dim_t dim,dim_t N,index_t* values) {
356     maybelong i,j,out,out_local;     dim_t i,j;
357     out=MAYBELONG_MAX;     index_t out,out_local;
358       out=INDEX_T_MAX;
359     if (values!=NULL && dim*N>0 ) {     if (values!=NULL && dim*N>0 ) {
360       out=values[0];       out=values[0];
361       #pragma omp parallel private(out_local)       #pragma omp parallel private(out_local)
# Line 373  maybelong Finley_Util_getMinInt(int dim, Line 374  maybelong Finley_Util_getMinInt(int dim,
374                                                                                                                                                                                                                                                                                                        
375  /* calculates the maximum value from a dim X N integer array */  /* calculates the maximum value from a dim X N integer array */
376    
377  maybelong Finley_Util_getMaxInt(int dim,int N,maybelong* values) {  index_t Finley_Util_getMaxInt(dim_t dim,dim_t N,index_t* values) {
378     maybelong i,j,out,out_local;     dim_t i,j;
379     out=-MAYBELONG_MAX;     index_t out,out_local;
380       out=-INDEX_T_MAX;
381     if (values!=NULL && dim*N>0 ) {     if (values!=NULL && dim*N>0 ) {
382       out=values[0];       out=values[0];
383       #pragma omp parallel private(out_local)       #pragma omp parallel private(out_local)
# Line 394  maybelong Finley_Util_getMaxInt(int dim, Line 396  maybelong Finley_Util_getMaxInt(int dim,
396    
397  /* 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. */
398    
399  maybelong Finley_Util_packMask(maybelong N,maybelong* mask,maybelong* index) {  dim_t Finley_Util_packMask(dim_t N,index_t* mask,index_t* index) {
400        maybelong out,k;        dim_t out,k;
401        out=0;        out=0;
402        /*OMP */        /*OMP */
403        for (k=0;k<N;k++) {        for (k=0;k<N;k++) {
# Line 408  maybelong Finley_Util_packMask(maybelong Line 410  maybelong Finley_Util_packMask(maybelong
410  }  }
411    
412  /* returns true if array contains value */  /* returns true if array contains value */
413  int Finley_Util_isAny(maybelong N,maybelong* array,maybelong value) {  bool_t Finley_Util_isAny(dim_t N,index_t* array,index_t value) {
414     int out=FALSE;     bool_t out=FALSE;
415     maybelong i;     dim_t i;
416     #pragma omp parallel for private(i) schedule(static) reduction(||:out)     #pragma omp parallel for private(i) schedule(static) reduction(||:out)
417     for (i=0;i<N;i++) out = out || (array[i]==value);     for (i=0;i<N;i++) out = out || (array[i]==value);
418     return out;     return out;
419  }  }
420  /* calculates the cummultative sum in array and returns the total sum */  /* calculates the cummultative sum in array and returns the total sum */
421  maybelong Finley_Util_cumsum(maybelong N,maybelong* array) {  index_t Finley_Util_cumsum(dim_t N,index_t* array) {
422     maybelong out=0,tmp,i;     index_t out=0,tmp;
423       dim_t i;
424     #ifdef _OPENMP     #ifdef _OPENMP
425        maybelong partial_sums[omp_get_max_threads()],sum;        index_t partial_sums[omp_get_max_threads()],sum;
426        #pragma omp parallel private(sum,i,tmp)        #pragma omp parallel private(sum,i,tmp)
427        {        {
428          sum=0;          sum=0;
# Line 455  maybelong Finley_Util_cumsum(maybelong N Line 458  maybelong Finley_Util_cumsum(maybelong N
458     return out;     return out;
459  }  }
460    
461  void Finley_copyDouble(int n,double* source, double* target) {  void Finley_copyDouble(dim_t n,double* source, double* target) {
462    int i;    dim_t i;
463    for (i=0;i<n;i++) target[i]=source[i];    for (i=0;i<n;i++) target[i]=source[i];
464  }  }
465    
466    /*
467     * $Log$
468     * Revision 1.7  2005/07/08 04:07:59  jgs
469     * Merge of development branch back to main trunk on 2005-07-08
470     *
471     * Revision 1.1.1.1.2.4  2005/06/29 02:34:57  gross
472     * some changes towards 64 integers in finley
473     *
474     * Revision 1.1.1.1.2.3  2005/03/02 23:35:06  gross
475     * reimplementation of the ILU in Finley. block size>1 still needs some testing
476     *
477     * Revision 1.1.1.1.2.2  2005/02/18 02:27:31  gross
478     * two function that will be used for a reimplementation of the ILU preconditioner
479     *
480     * Revision 1.1.1.1.2.1  2004/11/12 06:58:19  gross
481     * 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
482     *
483     * Revision 1.1.1.1  2004/10/26 06:53:57  jgs
484     * initial import of project esys2
485     *
486     * Revision 1.3  2004/08/26 12:03:52  gross
487     * Some other bug in Finley_Assemble_gradient fixed.
488     *
489     * Revision 1.2  2004/07/02 04:21:13  gross
490     * Finley C code has been included
491     *
492     * Revision 1.1.1.1  2004/06/24 04:00:40  johng
493     * Initial version of eys using boost-python.
494     *
495     *
496     */

Legend:
Removed from v.115  
changed lines
  Added in v.123

  ViewVC Help
Powered by ViewVC 1.1.26