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

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

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

revision 1028 by gross, Wed Mar 14 00:15:24 2007 UTC revision 1312 by ksteube, Mon Sep 24 06:18:44 2007 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: SystemMatrixPattern_unrollBlocks */
19    
20  /**************************************************************/  /**************************************************************/
21    
 /* Copyrights by ACcESS Australia 2003, 2004, 2005 */  
22  /* Author: gross@access.edu.au */  /* Author: gross@access.edu.au */
23    
24  /**************************************************************/  /**************************************************************/
25    
 #include "Paso.h"  
26  #include "SystemMatrixPattern.h"  #include "SystemMatrixPattern.h"
27    
28  /**************************************************************/  /**************************************************************/
29    
30  /* creates SystemMatrixPattern  */  /* creates SystemMatrixPattern  */
31    
32  Paso_SystemMatrixPattern* Paso_SystemMatrixPattern_unrollBlocks(Paso_SystemMatrixPattern* pattern, \  Paso_SystemMatrixPattern* Paso_SystemMatrixPattern_unrollBlocks(Paso_SystemMatrixPattern* pattern,
33                                             int type, dim_t row_block_size,dim_t col_block_size) {                                             int type, dim_t output_block_size,dim_t input_block_size) {
34    Paso_SystemMatrixPattern*out=NULL;    Paso_SystemMatrixPattern*out=NULL;
35    index_t *ptr=NULL,*index=NULL,iPtr;    Paso_Pattern *new_mainPattern=NULL, *new_couplePattern=NULL;
36    dim_t i,j,k,l, block_size, new_n_ptr, new_len;    Paso_Distribution* new_output_distribution=NULL, *new_input_distribution=NULL;
37    index_t index_offset_in=(pattern->type & PATTERN_FORMAT_OFFSET1 ? 1:0);    Paso_Coupler *new_coupler=NULL;
38    index_t index_offset_out=(type & PATTERN_FORMAT_OFFSET1 ? 1:0);  
39        new_mainPattern=Paso_Pattern_unrollBlocks(pattern->mainPattern,type,output_block_size,input_block_size);
40    if ((pattern->type & PATTERN_FORMAT_SYM) != (type & PATTERN_FORMAT_SYM)) {    new_couplePattern=Paso_Pattern_unrollBlocks(pattern->couplePattern,type,output_block_size,input_block_size);
41        Paso_setError(TYPE_ERROR,"Paso_SystemMatrixPattern_unrollBlocks: conversion between symmetric and non-symmetric is not implemented yet");    new_output_distribution=Paso_Distribution_alloc(pattern->output_distribution->mpi_info,
42        return NULL;                                                    pattern->output_distribution->first_component,
43                                                      output_block_size,0);
44      new_input_distribution=Paso_Distribution_alloc(pattern->input_distribution->mpi_info,
45                                                      pattern->input_distribution->first_component,
46                                                      input_block_size,0);
47      new_coupler=Paso_Coupler_unroll(pattern->coupler,input_block_size);
48      if (Paso_noError()) {
49         out=Paso_SystemMatrixPattern_alloc(type,
50                                            new_output_distribution,
51                                            new_input_distribution,
52                                            new_mainPattern,
53                                            new_couplePattern,
54                                            new_coupler);
55    }    }
56    Paso_resetError();    Paso_Pattern_free(new_mainPattern);
57    block_size=row_block_size*col_block_size;    Paso_Pattern_free(new_couplePattern);
58    new_n_ptr=(pattern->n_ptr)*row_block_size;    Paso_Distribution_free(new_output_distribution);
59    new_len=(pattern->len)*block_size;    Paso_Distribution_free(new_input_distribution);
60      Paso_Coupler_free(new_coupler);
61    ptr=MEMALLOC(new_n_ptr+1,index_t);  
62    index=MEMALLOC(new_len,index_t);    if (Paso_noError()) {
63         return out;
64      } else {
65    if (! ( Paso_checkPtr(ptr) || Paso_checkPtr(index) ) )  {       Paso_SystemMatrixPattern_free(out);
66       #pragma omp parallel       return NULL;
      {  
         #pragma omp for private(i) schedule(static)  
         for (i=0;i<new_n_ptr+1;++i) ptr[i]=index_offset_out;  
   
         #pragma omp master  
         ptr[new_n_ptr]=new_len+index_offset_out;  
   
         #pragma omp for private(i,k) schedule(static)  
         for (i=0;i<pattern->n_ptr;++i)  
             for (k=0;k<row_block_size;++k) ptr[i*row_block_size+k]=(pattern->ptr[i]-index_offset_in)*block_size+(pattern->ptr[i+1]-pattern->ptr[i])*col_block_size*k+index_offset_out;  
             
         #pragma omp for private(i,iPtr) schedule(static)  
         for (i=0;i<new_n_ptr;++i)  
             for (iPtr=ptr[i]-index_offset_out;iPtr<ptr[i+1]-index_offset_out;++iPtr) index[iPtr]=index_offset_out;  
   
         #pragma omp for private(i,j,iPtr,k) schedule(static)  
         for (i=0;i<pattern->n_ptr;++i) {  
            for (iPtr=pattern->ptr[i]-index_offset_in;iPtr<pattern->ptr[i+1]-index_offset_in;++iPtr)  {  
               for (k=0;k<row_block_size;++k) {  
                  for (j=0;j<col_block_size;++j) {  
                     index[ptr[i*row_block_size+k]-index_offset_out+(iPtr-(pattern->ptr[i]-index_offset_in))*col_block_size+j]=(pattern->index[iPtr]-index_offset_in)*col_block_size+j+index_offset_out;  
                  }  
               }  
            }  
         }  
      }  
      /* create return value */  
      out=Paso_SystemMatrixPattern_alloc(type,new_n_ptr,ptr,index);  
   }    
   if (! Paso_noError()) {  
      MEMFREE(index);  
      MEMFREE(ptr);  
67    }    }
   return out;  
68  }  }
 /*  
  * $Log$  
  * Revision 1.2  2005/09/15 03:44:39  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.1028  
changed lines
  Added in v.1312

  ViewVC Help
Powered by ViewVC 1.1.26