00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
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
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
00095
00096
00097
00098
00099
00100
00101
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
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}