/[escript]/trunk/paso/src/SystemMatrixPattern.c
ViewVC logotype

Diff of /trunk/paso/src/SystemMatrixPattern.c

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

trunk/paso/src/SystemMatrixPattern.c revision 631 by dhawcroft, Thu Mar 23 04:27:32 2006 UTC temp/paso/src/SystemMatrixPattern.c revision 1387 by trankine, Fri Jan 11 07:45:26 2008 UTC
# Line 1  Line 1 
1    
2  /* $Id$ */  /* $Id$ */
3    
4  /*  /*******************************************************
5  ********************************************************************************   *
6  *               Copyright 2006 by ACcESS MNRF                                *   *           Copyright 2003-2007 by ACceSS MNRF
7  *                                                                              *   *       Copyright 2007 by University of Queensland
8  *                 http://www.access.edu.au                                     *   *
9  *           Primary Business: Queensland, Australia                            *   *                http://esscc.uq.edu.au
10  *     Licensed under the Open Software License version 3.0             *   *        Primary Business: Queensland, Australia
11  *        http://www.opensource.org/licenses/osl-3.0.php                        *   *  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  /* Paso: SystemMatrixPatternPattern */  /* Paso: SystemMatrixPatternPattern */
19    
20  /**************************************************************/  /**************************************************************/
21    
22  /* Copyrights by ACcESS Australia 2003, 2004,2005 */  /* Copyrights by ACcESS Australia 2003, 2004,2005, 2006, 2007 */
23  /* Author: gross@access.edu.au */  /* Author: gross@access.edu.au */
24    
25  /**************************************************************/  /**************************************************************/
# Line 29  Line 31 
31    
32  /* allocates a SystemMatrixPattern  */  /* allocates a SystemMatrixPattern  */
33    
34  Paso_SystemMatrixPattern* Paso_SystemMatrixPattern_alloc(int type, int n_ptr, index_t* ptr,index_t* index) {  Paso_SystemMatrixPattern* Paso_SystemMatrixPattern_alloc(int type,
35    Paso_SystemMatrixPattern*out;                                                           Paso_Distribution *output_distribution,
36    index_t index_offset=(type & PATTERN_FORMAT_OFFSET1 ? 1:0);                                                           Paso_Distribution *input_distribution,
37    index_t loc_min_index,loc_max_index,min_index=index_offset,max_index=index_offset-1;                                                           Paso_Pattern* mainPattern,
38    dim_t i;                                                           Paso_Pattern* couplePattern,
39                                                             Paso_Coupler* coupler)
40    {
41      Paso_SystemMatrixPattern*out=NULL;
42    
43    
44    Paso_resetError();    Paso_resetError();
45    
46    if (type & PATTERN_FORMAT_SYM) {    if (mainPattern->type != type)  {
47      Paso_setError(TYPE_ERROR,"symmetric matrix pattern is not supported yet");        Paso_setError(VALUE_ERROR,"Paso_SystemMatrixPattern_alloc: type of mainPattern does not match expected type.");
48      return NULL;    }
49    }    if (couplePattern->type != type)  {
50    #pragma omp parallel private(loc_min_index,loc_max_index,i)        Paso_setError(VALUE_ERROR,"Paso_SystemMatrixPattern_alloc: type of couplePattern does not match expected type.");
51     {    }
52        loc_min_index=index_offset;    if ( couplePattern->numOutput != mainPattern->numOutput) {
53        loc_max_index=index_offset-1;              Paso_setError(VALUE_ERROR,"Paso_SystemMatrixPattern_alloc: number of output for couple and main pattern don't match.");
54        if (type & PATTERN_FORMAT_OFFSET1) {    }
55           #pragma omp for schedule(static)    if (mainPattern->numOutput !=  Paso_Distribution_getMyNumComponents(output_distribution)) {
56           for (i=0;i<n_ptr;++i) {        Paso_setError(VALUE_ERROR,"Paso_SystemMatrixPattern_alloc: number of output and given distribution don't match.");
57               if (ptr[i]<ptr[i+1]) {    }
58                 qsort(&(index[ptr[i]-1]),(size_t)(ptr[i+1]-ptr[i]),sizeof(index_t),Paso_comparIndex);    if (mainPattern->numInput != Paso_Distribution_getMyNumComponents(input_distribution)) {
59                 loc_min_index=MIN(loc_min_index,index[ptr[i]-1]);       Paso_setError(VALUE_ERROR,"Paso_SystemMatrixPattern_alloc: number of input for main pattern and number of send components in coupler don't match.");
60                 loc_max_index=MAX(loc_max_index,index[ptr[i+1]-2]);    }
61               }    if (couplePattern->numInput != coupler->recv->numSharedComponents) {
62           }       Paso_setError(VALUE_ERROR,"Paso_SystemMatrixPattern_alloc: number of inputs for couple pattern and number of received components in coupler don't match.");
63        } else {    }
64           #pragma omp for schedule(static)    if (mainPattern->output_block_size != couplePattern->output_block_size) {
65           for (i=0;i<n_ptr;++i) {       Paso_setError(VALUE_ERROR,"Paso_SystemMatrixPattern_alloc: output block sizes of main and couple pattern do not match.");
66               if (ptr[i]<ptr[i+1]) {    }
67                 qsort(&(index[ptr[i]]),(size_t)(ptr[i+1]-ptr[i]),sizeof(index_t),Paso_comparIndex);    if (mainPattern->input_block_size != couplePattern->input_block_size) {
68                 loc_min_index=MIN(loc_min_index,index[ptr[i]]);       Paso_setError(VALUE_ERROR,"Paso_SystemMatrixPattern_alloc: input block sizes of main and couple pattern do not match.");
                loc_max_index=MAX(loc_max_index,index[ptr[i+1]-1]);  
              }  
          }  
       }  
       #pragma omp critical  
       {  
          min_index=MIN(loc_min_index,min_index);  
          max_index=MAX(loc_max_index,max_index);  
       }  
   }  
   if (min_index<index_offset) {  
     Paso_setError(TYPE_ERROR,"Matrix pattern index out of range.");  
     return NULL;  
69    }    }
70    
71    out=MEMALLOC(1,Paso_SystemMatrixPattern);    out=MEMALLOC(1,Paso_SystemMatrixPattern);
72    if (Paso_checkPtr(out)) return NULL;    if (Paso_checkPtr(out)) return NULL;
   out->n_ptr=n_ptr;  
   out->n_index=max_index-index_offset+1;  
   out->ptr=ptr;  
   out->index=index;  
   out->len=out->ptr[out->n_ptr]-index_offset;  
   out->reference_counter=1;  
73    out->type=type;    out->type=type;
74      out->reference_counter=1;
75      out->mainPattern=Paso_Pattern_getReference(mainPattern);
76      out->couplePattern=Paso_Pattern_getReference(couplePattern);
77      out->coupler=Paso_Coupler_getReference(coupler);
78      out->output_distribution=Paso_Distribution_getReference(output_distribution);
79      out->input_distribution=Paso_Distribution_getReference(input_distribution);
80      out->mpi_info= Paso_MPIInfo_getReference(coupler->mpi_info);
81    #ifdef Paso_TRACE    #ifdef Paso_TRACE
82    printf("Paso_SystemMatrixPattern_dealloc: system matrix pattern as been allocated.\n");    printf("Paso_SystemMatrixPattern_dealloc: system matrix pattern as been allocated.\n");
83    #endif    #endif
# Line 100  Paso_SystemMatrixPattern* Paso_SystemMat Line 95  Paso_SystemMatrixPattern* Paso_SystemMat
95        
96  /* deallocates a SystemMatrixPattern: */  /* deallocates a SystemMatrixPattern: */
97    
98  void Paso_SystemMatrixPattern_dealloc(Paso_SystemMatrixPattern* in) {  void Paso_SystemMatrixPattern_free(Paso_SystemMatrixPattern* in) {
99    if (in!=NULL) {    if (in!=NULL) {
100       in->reference_counter--;       in->reference_counter--;
101       if (in->reference_counter<=0) {       if (in->reference_counter<=0) {
102          MEMFREE(in->ptr);          Paso_Pattern_free(in->mainPattern);
103          MEMFREE(in->index);          Paso_Pattern_free(in->couplePattern);
104            Paso_Coupler_free(in->coupler);
105            Paso_Distribution_free(in->output_distribution);
106            Paso_Distribution_free(in->input_distribution);
107            Paso_MPIInfo_free(in->mpi_info);
108          MEMFREE(in);          MEMFREE(in);
109          #ifdef Paso_TRACE          #ifdef Paso_TRACE
110          printf("Paso_SystemMatrixPattern_dealloc: system matrix pattern as been deallocated.\n");          printf("Paso_SystemMatrixPattern_free: system matrix pattern as been deallocated.\n");
111          #endif          #endif
112       }       }
113     }     }
114  }  }
115  /* *************************************************************/  dim_t Paso_SystemMatrixPattern_getNumOutput(Paso_SystemMatrixPattern* in) {
116        if (in!=NULL) {
117  /*  some routines which help to get the matrix pattern from elements: */         return 0;
118        } else {
119  /*  this routine is used by qsort called in Paso_SystemMatrixPattern_alloc */         return in->mainPattern->numOutput;
120        }
 int Paso_comparIndex(const void *index1,const void *index2){  
    index_t Iindex1,Iindex2;  
    Iindex1=*(index_t*)index1;  
    Iindex2=*(index_t*)index2;  
    if (Iindex1<Iindex2) {  
       return -1;  
    } else {  
       if (Iindex1>Iindex2) {  
          return 1;  
       } else {  
          return 0;  
       }  
    }  
121  }  }
122  /*  
  * $Log$  
  * Revision 1.2  2005/09/15 03:44:38  jgs  
  * Merge of development branch dev-02 back to main trunk on 2005-09-15  
  *  
  * Revision 1.1.2.1  2005/09/05 06:29:47  gross  
  * These files have been extracted from finley to define a stand alone libray for iterative  
  * linear solvers on the ALTIX. main entry through Paso_solve. this version compiles but  
  * has not been tested yet.  
  *  
  *  
  */  

Legend:
Removed from v.631  
changed lines
  Added in v.1387

  ViewVC Help
Powered by ViewVC 1.1.26