IFPACK  Development
 All Classes Files Functions Variables Enumerations Friends
getRow_dh.c
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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ***********************************************************************
00040 //@HEADER
00041 */
00042 
00043 #include "getRow_dh.h"
00044 #include "Mat_dh.h"
00045 #include "Euclid_dh.h"
00046 #include "Mem_dh.h"
00047 
00048 
00049 /*-------------------------------------------------------------------
00050  *  EPETRA
00051  *-------------------------------------------------------------------*/
00052 
00053 #undef __FUNC__
00054 #define __FUNC__ "EuclidGetRow"
00055 void
00056 EuclidGetRow (void *A, int row, int *len, int **ind, double **val)
00057 {
00058   START_FUNC_DH int ierr = 0;
00059   if (ind != NULL)
00060     ierr += ExtractIndicesView (A, row, len, ind);
00061   if (ierr != 0)
00062     {
00063       sprintf (msgBuf_dh, "ExtractIndicesView(row= %i) returned %i", row + 1,
00064            ierr);
00065       SET_V_ERROR (msgBuf_dh);
00066     }
00067   if (val != NULL)
00068     ierr += ExtractValuesView (A, row, len, val);
00069   if (ierr != 0)
00070     {
00071       sprintf (msgBuf_dh, " ExtractValuesView(row= %i) returned %i", row + 1,
00072            ierr);
00073       SET_V_ERROR (msgBuf_dh);
00074     }
00075 END_FUNC_DH}
00076 
00077 #undef __FUNC__
00078 #define __FUNC__ "EuclidRestoreRow"
00079 void
00080 EuclidRestoreRow (void *A, int row, int *len, int **ind, double **val)
00081 {
00082   START_FUNC_DH
00083     /* This is needed in Hypre and Petsc, but not Trilinos. */
00084 END_FUNC_DH}
00085 
00086 #undef __FUNC__
00087 #define __FUNC__ "EuclidGetDimensions"
00088 void
00089 EuclidGetDimensions (void *A, int *beg_row, int *rowsLocal, int *rowsGlobal)
00090 {
00091   START_FUNC_DH int m, n;
00092   int row_start, row_end, col_start, col_end;
00093 
00094   row_start = MinMaxMyGID (A, true, true);
00095   row_end = MinMaxMyGID (A, true, false);
00096   col_start = MinMaxMyGID (A, false, true);
00097   col_end = MinMaxMyGID (A, false, false);
00098 
00099   m = NumGlobalRowCol (A, false);
00100   n = NumGlobalRowCol (A, true);
00101   *beg_row = row_start;
00102   *rowsLocal = (row_end - row_start + 1);
00103   *rowsGlobal = n;
00104 END_FUNC_DH}
00105 
00106 /*
00107 #undef __FUNC__
00108 #define __FUNC__ "EuclidReadLocalNz"
00109 int EuclidReadLocalNz(void *A)
00110 {
00111   START_FUNC_DH
00112   if (ignoreMe) SET_V_ERROR("not implemented");
00113   return(0);
00114   END_FUNC_DH
00115 }
00116 */
00117 
00118 #undef __FUNC__
00119 #define __FUNC__ "PrintMatUsingGetRow"
00120 void
00121 PrintMatUsingGetRow (void *A, int beg_row, int m,
00122              int *n2o_row, int *n2o_col, char *filename)
00123 {
00124   START_FUNC_DH FILE *fp;
00125   int *o2n_col = NULL, pe, i, j, *cval, len;
00126   int newCol, newRow;
00127   double *aval;
00128 
00129   /* form inverse column permutation */
00130   if (n2o_col != NULL)
00131     {
00132       o2n_col = (int *) MALLOC_DH (m * sizeof (int));
00133       CHECK_V_ERROR;
00134       for (i = 0; i < m; ++i)
00135     o2n_col[n2o_col[i]] = i;
00136     }
00137 
00138   for (pe = 0; pe < np_dh; ++pe)
00139     {
00140 
00141       MPI_Barrier (comm_dh);
00142 
00143       if (myid_dh == pe)
00144     {
00145       if (pe == 0)
00146         {
00147           fp = fopen (filename, "w");
00148         }
00149       else
00150         {
00151           fp = fopen (filename, "a");
00152         }
00153       if (fp == NULL)
00154         {
00155           sprintf (msgBuf_dh, "can't open %s for writing\n", filename);
00156           SET_V_ERROR (msgBuf_dh);
00157         }
00158 
00159       for (i = 0; i < m; ++i)
00160         {
00161 
00162           if (n2o_row == NULL)
00163         {
00164           EuclidGetRow (A, i + beg_row, &len, &cval, &aval);
00165           CHECK_V_ERROR;
00166           for (j = 0; j < len; ++j)
00167             {
00168               fprintf (fp, "%i %i %g\n", i + 1, cval[j], aval[j]);
00169             }
00170           EuclidRestoreRow (A, i, &len, &cval, &aval);
00171           CHECK_V_ERROR;
00172         }
00173           else
00174         {
00175           newRow = n2o_row[i] + beg_row;
00176           EuclidGetRow (A, newRow, &len, &cval, &aval);
00177           CHECK_V_ERROR;
00178           for (j = 0; j < len; ++j)
00179             {
00180               newCol = o2n_col[cval[j] - beg_row] + beg_row;
00181               fprintf (fp, "%i %i %g\n", i + 1, newCol, aval[j]);
00182             }
00183           EuclidRestoreRow (A, i, &len, &cval, &aval);
00184           CHECK_V_ERROR;
00185         }
00186         }
00187       fclose (fp);
00188     }
00189     }
00190 
00191   if (n2o_col != NULL)
00192     {
00193       FREE_DH (o2n_col);
00194       CHECK_V_ERROR;
00195     }
00196 END_FUNC_DH}
 All Classes Files Functions Variables Enumerations Friends