getRow_dh.c

00001 /*@HEADER
00002 // ***********************************************************************
00003 //
00004 //       Ifpack: Object-Oriented Algebraic Preconditioner Package
00005 //                 Copyright (2009) 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 "getRow_dh.h"
00031 #include "Mat_dh.h"
00032 #include "Euclid_dh.h"
00033 #include "Mem_dh.h"
00034 
00035 
00036 /*-------------------------------------------------------------------
00037  *  EPETRA
00038  *-------------------------------------------------------------------*/
00039 
00040 #undef __FUNC__
00041 #define __FUNC__ "EuclidGetRow"
00042 void
00043 EuclidGetRow (void *A, int row, int *len, int **ind, double **val)
00044 {
00045   START_FUNC_DH int ierr = 0;
00046   if (ind != NULL)
00047     ierr += ExtractIndicesView (A, row, len, ind);
00048   if (ierr != 0)
00049     {
00050       sprintf (msgBuf_dh, "ExtractIndicesView(row= %i) returned %i", row + 1,
00051            ierr);
00052       SET_V_ERROR (msgBuf_dh);
00053     }
00054   if (val != NULL)
00055     ierr += ExtractValuesView (A, row, len, val);
00056   if (ierr != 0)
00057     {
00058       sprintf (msgBuf_dh, " ExtractValuesView(row= %i) returned %i", row + 1,
00059            ierr);
00060       SET_V_ERROR (msgBuf_dh);
00061     }
00062 END_FUNC_DH}
00063 
00064 #undef __FUNC__
00065 #define __FUNC__ "EuclidRestoreRow"
00066 void
00067 EuclidRestoreRow (void *A, int row, int *len, int **ind, double **val)
00068 {
00069   START_FUNC_DH
00070     /* This is needed in Hypre and Petsc, but not Trilinos. */
00071 END_FUNC_DH}
00072 
00073 #undef __FUNC__
00074 #define __FUNC__ "EuclidGetDimensions"
00075 void
00076 EuclidGetDimensions (void *A, int *beg_row, int *rowsLocal, int *rowsGlobal)
00077 {
00078   START_FUNC_DH int m, n;
00079   int row_start, row_end, col_start, col_end;
00080 
00081   row_start = MinMaxMyGID (A, true, true);
00082   row_end = MinMaxMyGID (A, true, false);
00083   col_start = MinMaxMyGID (A, false, true);
00084   col_end = MinMaxMyGID (A, false, false);
00085 
00086   m = NumGlobalRowCol (A, false);
00087   n = NumGlobalRowCol (A, true);
00088   *beg_row = row_start;
00089   *rowsLocal = (row_end - row_start + 1);
00090   *rowsGlobal = n;
00091 END_FUNC_DH}
00092 
00093 /*
00094 #undef __FUNC__
00095 #define __FUNC__ "EuclidReadLocalNz"
00096 int EuclidReadLocalNz(void *A)
00097 {
00098   START_FUNC_DH
00099   if (ignoreMe) SET_V_ERROR("not implemented");
00100   return(0);
00101   END_FUNC_DH
00102 }
00103 */
00104 
00105 #undef __FUNC__
00106 #define __FUNC__ "PrintMatUsingGetRow"
00107 void
00108 PrintMatUsingGetRow (void *A, int beg_row, int m,
00109              int *n2o_row, int *n2o_col, char *filename)
00110 {
00111   START_FUNC_DH FILE *fp;
00112   int *o2n_col = NULL, pe, i, j, *cval, len;
00113   int newCol, newRow;
00114   double *aval;
00115 
00116   /* form inverse column permutation */
00117   if (n2o_col != NULL)
00118     {
00119       o2n_col = (int *) MALLOC_DH (m * sizeof (int));
00120       CHECK_V_ERROR;
00121       for (i = 0; i < m; ++i)
00122     o2n_col[n2o_col[i]] = i;
00123     }
00124 
00125   for (pe = 0; pe < np_dh; ++pe)
00126     {
00127 
00128       MPI_Barrier (comm_dh);
00129 
00130       if (myid_dh == pe)
00131     {
00132       if (pe == 0)
00133         {
00134           fp = fopen (filename, "w");
00135         }
00136       else
00137         {
00138           fp = fopen (filename, "a");
00139         }
00140       if (fp == NULL)
00141         {
00142           sprintf (msgBuf_dh, "can't open %s for writing\n", filename);
00143           SET_V_ERROR (msgBuf_dh);
00144         }
00145 
00146       for (i = 0; i < m; ++i)
00147         {
00148 
00149           if (n2o_row == NULL)
00150         {
00151           EuclidGetRow (A, i + beg_row, &len, &cval, &aval);
00152           CHECK_V_ERROR;
00153           for (j = 0; j < len; ++j)
00154             {
00155               fprintf (fp, "%i %i %g\n", i + 1, cval[j], aval[j]);
00156             }
00157           EuclidRestoreRow (A, i, &len, &cval, &aval);
00158           CHECK_V_ERROR;
00159         }
00160           else
00161         {
00162           newRow = n2o_row[i] + beg_row;
00163           EuclidGetRow (A, newRow, &len, &cval, &aval);
00164           CHECK_V_ERROR;
00165           for (j = 0; j < len; ++j)
00166             {
00167               newCol = o2n_col[cval[j] - beg_row] + beg_row;
00168               fprintf (fp, "%i %i %g\n", i + 1, newCol, aval[j]);
00169             }
00170           EuclidRestoreRow (A, i, &len, &cval, &aval);
00171           CHECK_V_ERROR;
00172         }
00173         }
00174       fclose (fp);
00175     }
00176     }
00177 
00178   if (n2o_col != NULL)
00179     {
00180       FREE_DH (o2n_col);
00181       CHECK_V_ERROR;
00182     }
00183 END_FUNC_DH}

Generated on Wed May 12 21:30:17 2010 for IFPACK by  doxygen 1.4.7