/[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

revision 631 by dhawcroft, Thu Mar 23 04:27:32 2006 UTC revision 1811 by ksteube, Thu Sep 25 23:11:13 2008 UTC
# Line 1  Line 1 
 /* $Id$ */  
1    
2  /*  /*******************************************************
3  ********************************************************************************  *
4  *               Copyright 2006 by ACcESS MNRF                                *  * Copyright (c) 2003-2008 by University of Queensland
5  *                                                                              *  * Earth Systems Science Computational Center (ESSCC)
6  *                 http://www.access.edu.au                                     *  * http://www.uq.edu.au/esscc
7  *           Primary Business: Queensland, Australia                            *  *
8  *     Licensed under the Open Software License version 3.0             *  * Primary Business: Queensland, Australia
9  *        http://www.opensource.org/licenses/osl-3.0.php                        *  * Licensed under the Open Software License version 3.0
10  ********************************************************************************  * http://www.opensource.org/licenses/osl-3.0.php
11  */  *
12    *******************************************************/
13    
14    
15  /**************************************************************/  /**************************************************************/
16    
17  /* Paso: SystemMatrixPatternPattern */  /* Paso: SystemMatrixPatternPattern */
18    
19  /**************************************************************/  /**************************************************************/
20    
 /* Copyrights by ACcESS Australia 2003, 2004,2005 */  
21  /* Author: gross@access.edu.au */  /* Author: gross@access.edu.au */
22    
23  /**************************************************************/  /**************************************************************/
# Line 29  Line 29 
29    
30  /* allocates a SystemMatrixPattern  */  /* allocates a SystemMatrixPattern  */
31    
32  Paso_SystemMatrixPattern* Paso_SystemMatrixPattern_alloc(int type, int n_ptr, index_t* ptr,index_t* index) {  Paso_SystemMatrixPattern* Paso_SystemMatrixPattern_alloc(int type,
33    Paso_SystemMatrixPattern*out;                                                           Paso_Distribution *output_distribution,
34    index_t index_offset=(type & PATTERN_FORMAT_OFFSET1 ? 1:0);                                                           Paso_Distribution *input_distribution,
35    index_t loc_min_index,loc_max_index,min_index=index_offset,max_index=index_offset-1;                                                           Paso_Pattern* mainPattern,
36    dim_t i;                                                           Paso_Pattern* col_couplePattern,
37                                                             Paso_Pattern* row_couplePattern,
38                                                             Paso_Connector* col_connector,
39                                                             Paso_Connector* row_connector)
40    {
41      Paso_SystemMatrixPattern*out=NULL;
42    Paso_resetError();    Paso_resetError();
43    
44    if (type & PATTERN_FORMAT_SYM) {    if (output_distribution->mpi_info != input_distribution->mpi_info ) {
45      Paso_setError(TYPE_ERROR,"symmetric matrix pattern is not supported yet");       Paso_setError(SYSTEM_ERROR,"Paso_SystemMatrixPattern_alloc: output_distribution and input_distribution mpi communicator don't match.");
46      return NULL;       return NULL;
47    }    }
48    #pragma omp parallel private(loc_min_index,loc_max_index,i)    if (output_distribution->mpi_info != col_connector->mpi_info ) {
49     {       Paso_setError(SYSTEM_ERROR,"Paso_SystemMatrixPattern_alloc: output_distribution and col_connector mpi communicator don't match.");
50        loc_min_index=index_offset;       return NULL;
51        loc_max_index=index_offset-1;    }
52        if (type & PATTERN_FORMAT_OFFSET1) {    if (output_distribution->mpi_info != row_connector->mpi_info ) {
53           #pragma omp for schedule(static)       Paso_setError(SYSTEM_ERROR,"Paso_SystemMatrixPattern_alloc: output_distribution and row_connector mpi communicator don't match.");
54           for (i=0;i<n_ptr;++i) {       return NULL;
55               if (ptr[i]<ptr[i+1]) {    }
56                 qsort(&(index[ptr[i]-1]),(size_t)(ptr[i+1]-ptr[i]),sizeof(index_t),Paso_comparIndex);  
57                 loc_min_index=MIN(loc_min_index,index[ptr[i]-1]);  
58                 loc_max_index=MAX(loc_max_index,index[ptr[i+1]-2]);    if (mainPattern->type != type)  {
59               }        Paso_setError(VALUE_ERROR,"Paso_SystemMatrixPattern_alloc: type of mainPattern does not match expected type.");
60           }    }
61        } else {    if (col_couplePattern->type != type)  {
62           #pragma omp for schedule(static)        Paso_setError(VALUE_ERROR,"Paso_SystemMatrixPattern_alloc: type of col_couplePattern does not match expected type.");
63           for (i=0;i<n_ptr;++i) {    }
64               if (ptr[i]<ptr[i+1]) {    if (row_couplePattern->type != type)  {
65                 qsort(&(index[ptr[i]]),(size_t)(ptr[i+1]-ptr[i]),sizeof(index_t),Paso_comparIndex);        Paso_setError(VALUE_ERROR,"Paso_SystemMatrixPattern_alloc: type of row_couplePattern does not match expected type.");
66                 loc_min_index=MIN(loc_min_index,index[ptr[i]]);    }
67                 loc_max_index=MAX(loc_max_index,index[ptr[i+1]-1]);    if (col_couplePattern->numOutput != mainPattern->numOutput) {
68               }              Paso_setError(VALUE_ERROR,"Paso_SystemMatrixPattern_alloc: number of output for couple and main pattern don't match.");
69           }    }
70        }    if (mainPattern->numOutput !=  Paso_Distribution_getMyNumComponents(output_distribution)) {
71        #pragma omp critical        Paso_setError(VALUE_ERROR,"Paso_SystemMatrixPattern_alloc: number of output and given distribution don't match.");
72        {    }
73           min_index=MIN(loc_min_index,min_index);    if (mainPattern->numInput != Paso_Distribution_getMyNumComponents(input_distribution)) {
74           max_index=MAX(loc_max_index,max_index);       Paso_setError(VALUE_ERROR,"Paso_SystemMatrixPattern_alloc: number of input for main pattern and number of send components in connector don't match.");
75        }    }
76    }    if (col_couplePattern->numInput != col_connector->recv->numSharedComponents) {
77    if (min_index<index_offset) {       Paso_setError(VALUE_ERROR,"Paso_SystemMatrixPattern_alloc: number of inputs for column couple pattern and number of received components in connector don't match.");
78      Paso_setError(TYPE_ERROR,"Matrix pattern index out of range.");    }
79      return NULL;    if (row_couplePattern->numOutput != row_connector->recv->numSharedComponents) {
80         Paso_setError(VALUE_ERROR,"Paso_SystemMatrixPattern_alloc: number of inputs for row couple pattern and number of received components in connector don't match.");
81      }
82      if (mainPattern->output_block_size != col_couplePattern->output_block_size) {
83         Paso_setError(VALUE_ERROR,"Paso_SystemMatrixPattern_alloc: output block sizes of main and column couple pattern do not match.");
84      }
85      if (mainPattern->input_block_size != col_couplePattern->input_block_size) {
86         Paso_setError(VALUE_ERROR,"Paso_SystemMatrixPattern_alloc: input block sizes of main and column couple pattern do not match.");
87      }
88      if (mainPattern->output_block_size != row_couplePattern->output_block_size) {
89         Paso_setError(VALUE_ERROR,"Paso_SystemMatrixPattern_alloc: output block sizes of main and row couple pattern do not match.");
90      }
91      if (mainPattern->input_block_size != col_couplePattern->input_block_size) {
92         Paso_setError(VALUE_ERROR,"Paso_SystemMatrixPattern_alloc: input block sizes of main and row couple pattern do not match.");
93    }    }
94    
95    out=MEMALLOC(1,Paso_SystemMatrixPattern);    out=MEMALLOC(1,Paso_SystemMatrixPattern);
96    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;  
97    out->type=type;    out->type=type;
98      out->reference_counter=1;
99      out->mainPattern=Paso_Pattern_getReference(mainPattern);
100      out->row_couplePattern=Paso_Pattern_getReference(row_couplePattern);
101      out->col_couplePattern=Paso_Pattern_getReference(col_couplePattern);
102      out->row_connector=Paso_Connector_getReference(row_connector);
103      out->col_connector=Paso_Connector_getReference(col_connector);
104      out->output_distribution=Paso_Distribution_getReference(output_distribution);
105      out->input_distribution=Paso_Distribution_getReference(input_distribution);
106      out->mpi_info= Paso_MPIInfo_getReference(output_distribution->mpi_info);
107    #ifdef Paso_TRACE    #ifdef Paso_TRACE
108    printf("Paso_SystemMatrixPattern_dealloc: system matrix pattern as been allocated.\n");    printf("Paso_SystemMatrixPattern_dealloc: system matrix pattern as been allocated.\n");
109    #endif    #endif
# Line 100  Paso_SystemMatrixPattern* Paso_SystemMat Line 121  Paso_SystemMatrixPattern* Paso_SystemMat
121        
122  /* deallocates a SystemMatrixPattern: */  /* deallocates a SystemMatrixPattern: */
123    
124  void Paso_SystemMatrixPattern_dealloc(Paso_SystemMatrixPattern* in) {  void Paso_SystemMatrixPattern_free(Paso_SystemMatrixPattern* in) {
125    if (in!=NULL) {    if (in!=NULL) {
126       in->reference_counter--;       in->reference_counter--;
127       if (in->reference_counter<=0) {       if (in->reference_counter<=0) {
128          MEMFREE(in->ptr);          Paso_Pattern_free(in->mainPattern);
129          MEMFREE(in->index);          Paso_Pattern_free(in->row_couplePattern);
130            Paso_Pattern_free(in->col_couplePattern);
131            Paso_Connector_free(in->row_connector);
132            Paso_Connector_free(in->col_connector);
133            Paso_Distribution_free(in->output_distribution);
134            Paso_Distribution_free(in->input_distribution);
135            Paso_MPIInfo_free(in->mpi_info);
136          MEMFREE(in);          MEMFREE(in);
137          #ifdef Paso_TRACE          #ifdef Paso_TRACE
138          printf("Paso_SystemMatrixPattern_dealloc: system matrix pattern as been deallocated.\n");          printf("Paso_SystemMatrixPattern_free: system matrix pattern as been deallocated.\n");
139          #endif          #endif
140       }       }
141     }     }
142  }  }
143  /* *************************************************************/  dim_t Paso_SystemMatrixPattern_getNumOutput(Paso_SystemMatrixPattern* in) {
144        if (in!=NULL) {
145  /*  some routines which help to get the matrix pattern from elements: */         return 0;
146        } else {
147  /*  this routine is used by qsort called in Paso_SystemMatrixPattern_alloc */         return in->mainPattern->numOutput;
148        }
 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;  
       }  
    }  
149  }  }
 /*  
  * $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.1811

  ViewVC Help
Powered by ViewVC 1.1.26