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
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
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
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
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
00108
00109
00110
00111
00112
00113
00114
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
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}