create_vbr.c

Go to the documentation of this file.
00001 /*@HEADER
00002 // ***********************************************************************
00003 // 
00004 //       Ifpack: Object-Oriented Algebraic Preconditioner Package
00005 //                 Copyright (2002) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 //@HEADER
00028 */
00029 
00030 #include <stdlib.h>
00031 #include <stdio.h>
00032 #include "paz_aztec.h"
00033 
00034 void create_vbr(char *partition_file, int *proc_config,
00035     int *N_global, int *N_blk_global, 
00036     int *n_nonzeros, int *n_blk_nonzeros,
00037     int *N_update, int **update,
00038     int *bindx_msr, double *val_msr,
00039     double **val, int **indx, int **rpntr, int **cpntr,
00040     int **bpntr, int **bindx)
00041 #undef DEBUG 
00042      /*  read ASCII data file:
00043    line 1: N_global, number of entries (%d,%d)
00044    line 2-...: i,j,real (%d, %d, %f)
00045      */
00046 
00047 {
00048   FILE *data ;
00049 
00050 
00051   int i, n_entries, N_columns;
00052   int ii, jj ;
00053   int kk = 0;
00054   int max_ii = 0, max_jj = 0;
00055   int ione = 1;
00056   double value;
00057   double *cnt;
00058   int *pntr, *indx1, *pntr1;
00059   double *val1;
00060   int blocksize, N_blk_equations, N_block_entries, n_vbr_nonzeros, n_msr_nonzeros;
00061   int total_msr_storage, total_vbr_storage;
00062   int variable_block_size, blk_type;
00063   int cur_blk_ptr=0, prev_blk_ptr;
00064 
00065   if(proc_config[PAZ_node] == 0) 
00066     { 
00067 
00068       /* Do case where command line argument is an integer.
00069    Interpret integer as the constant block size */
00070       printf("***************************************************************\n");
00071       if (partition_file[0] >='0' && partition_file[0] <='9')
00072   {
00073     blocksize = atoi(partition_file);
00074     printf("Using block size of %d to convert from MSR to VBR\n",blocksize);
00075     N_blk_equations = *N_global/blocksize;
00076 
00077     /* Allocate memory for cpntr */
00078     *cpntr = (int   *) calloc(N_blk_equations+2,sizeof(int)) ;
00079 
00080     /* Define block sizes for all but last equation */
00081     for (i=0; i<N_blk_equations; i++) (*cpntr)[i] = blocksize;
00082 
00083     /* Check if number of equations is multiple of blocksize */
00084     variable_block_size = *N_global%blocksize;
00085     blk_type = blocksize;
00086 
00087     if (variable_block_size)
00088       {
00089         N_blk_equations ++;
00090         (*cpntr)[N_blk_equations-1] = variable_block_size;
00091         blk_type = -blocksize;
00092       }
00093   }
00094       else
00095   {
00096     /* Otherwise command line arg is a file name containing partition 
00097        information.  
00098        The first line of the file must be the integer value zero.
00099        The last line of the file must equal the number of global equations,
00100        i.e., N_global.
00101        Lines in between are incremented by the number of equations per
00102              block row.
00103     */
00104     /* This should be a short file, so read once to get number of block
00105        equations, then read again to fill values */
00106     printf("Using partition from %s to convert from MSR to VBR\n",
00107      partition_file);
00108     data = fopen(partition_file,"r") ;
00109     N_blk_equations = 0;
00110     while(cur_blk_ptr !=*N_global)
00111       {
00112         fscanf(data, "%d", &cur_blk_ptr);
00113         N_blk_equations++;
00114       }
00115     close(data);
00116 
00117     /* Allocate memory for cpntr */
00118     *cpntr = (int   *) calloc(N_blk_equations+1,sizeof(int)) ;
00119 
00120     N_blk_equations = 0;
00121     data = fopen(partition_file,"r") ;
00122     fscanf(data, "%d", &prev_blk_ptr);
00123     cur_blk_ptr = 0;
00124     while(cur_blk_ptr !=*N_global)
00125       {
00126         fscanf(data, "%d", &cur_blk_ptr);
00127         (*cpntr)[N_blk_equations] = cur_blk_ptr - prev_blk_ptr;
00128         prev_blk_ptr = cur_blk_ptr;
00129         N_blk_equations++;
00130       }
00131     close(data);
00132     blk_type = -1; /* assume variable block for now */
00133     
00134   }
00135 
00136       /* Estimate storage needed for VBR and allocate space */
00137 
00138       N_block_entries = *n_nonzeros;
00139       n_vbr_nonzeros = min(abs(*n_nonzeros * blocksize * blocksize),
00140          420000000/8);
00141       *N_blk_global = N_blk_equations;
00142 
00143       printf("\nEstimated Storage parameters for VBR:\n");
00144       printf("   Number of block  equations = %d\n",N_blk_equations);
00145       printf("   Number of block  entries   = %d\n",N_block_entries);
00146       printf("   Number of scalar entries   = %d\n",n_vbr_nonzeros);
00147   
00148       
00149       *bpntr = (int   *) calloc(N_blk_equations+1,sizeof(int)) ;
00150       *rpntr = (int   *) calloc(N_blk_equations+1,sizeof(int)) ;
00151       *bindx = (int   *) calloc(N_block_entries+1,sizeof(int)) ;
00152       *indx  = (int   *) calloc(N_block_entries+1,sizeof(int)) ;
00153       *val = (double *) calloc(n_vbr_nonzeros+1,  sizeof(double)) ;
00154   
00155       
00156       while (n_vbr_nonzeros >= *n_nonzeros && (*val) == NULL)
00157   {
00158     printf("Error: Unable to allocate %d bytes to create VBR matrix.\n",
00159      n_vbr_nonzeros*sizeof(double));
00160     printf("       Trying to allocate %d bytes.\n",
00161      n_vbr_nonzeros*sizeof(double)/2);
00162     n_vbr_nonzeros /= 2;
00163     *val = (double *) calloc(n_vbr_nonzeros+1,  sizeof(double)) ;
00164   }
00165 
00166       PAZ_msr2vbr(*val, *indx, *rpntr, *cpntr, *bpntr, *bindx, bindx_msr,val_msr, 
00167      N_blk_equations, N_blk_equations, N_block_entries,
00168      n_vbr_nonzeros, blk_type);
00169 
00170       n_msr_nonzeros = *n_nonzeros;
00171 
00172       *n_nonzeros = (*indx)[(*bpntr)[*N_blk_global]];
00173       *n_blk_nonzeros = (*bpntr)[*N_blk_global];
00174       
00175       *bindx = (int   *) realloc((void *) (*bindx),
00176          (*n_blk_nonzeros+1)*sizeof(int)) ;
00177       *indx  = (int   *) realloc((void *) (*indx),
00178          (*n_blk_nonzeros+1)*sizeof(int)) ;
00179       *val = (double *) realloc((void *) (*val),
00180         (*n_nonzeros+1)*sizeof(double)) ;
00181       printf("\nActual Storage parameters for VBR:\n");
00182       printf("   Number of block  equations = %d\n",N_blk_equations);
00183       printf("   Number of block  entries   = %d\n",*n_blk_nonzeros);
00184       printf("   Number of scalar entries   = %d\n",*n_nonzeros);
00185       
00186       total_msr_storage = 4*  (n_msr_nonzeros+1)  +   8*(n_msr_nonzeros+1);
00187       total_vbr_storage = 4*3*(N_blk_equations+1) + 4*2*(*n_blk_nonzeros+1) + 
00188                     8*(*n_nonzeros);
00189       printf("\nTotal MSR storage (bytes)   = %d\n",total_msr_storage);
00190       printf(  "Total VBR storage (bytes)   = %d\n",total_vbr_storage);
00191       printf(  "Ratio of VBR to MSR storage = %5.2f\n",
00192        (float)total_vbr_storage/(float)total_msr_storage);
00193 
00194   
00195       printf("***************************************************************\n");
00196     }
00197   /* end create_vbr */
00198 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Wed Apr 13 10:05:33 2011 for Ifpack Package Browser (Single Doxygen Collection) by  doxygen 1.6.3