42 #include "Epetra_Comm.h" 43 #include "Epetra_Util.h" 44 #include "Epetra_BlockMap.h" 45 #include "Epetra_Map.h" 46 #include "Epetra_IntVector.h" 47 #include "Epetra_IntSerialDenseVector.h" 48 #include "Epetra_Import.h" 56 Epetra_BlockMap * bmap;
58 map =
dynamic_cast<Epetra_Map *
>(bmap);
64 const int lineLength = 1025;
65 char line[lineLength];
66 char token[lineLength];
67 int M, N, numProc, MaxElementSize, MinElementSize, NumMyElements, IndexBase, NumGlobalElements, firstGid;
73 handle = fopen(filename,
"r");
78 if(fgets(line, lineLength, handle)==0)
return(-1);
79 if(sscanf(line,
"%s", token)==0)
return(-1);
80 if (!strcmp(token,
"%NumProc:")) inHeader =
false;
83 if(fgets(line, lineLength, handle)==0)
return(-1);
84 if(sscanf(line,
"%s %d", token, &numProc)==0)
return(-1);
86 if(fgets(line, lineLength, handle)==0)
return(-1);
87 if(fgets(line, lineLength, handle)==0)
return(-1);
88 if(sscanf(line,
"%s %d", token, &MaxElementSize)==0)
return(-1);
90 if(fgets(line, lineLength, handle)==0)
return(-1);
91 if(fgets(line, lineLength, handle)==0)
return(-1);
92 if(sscanf(line,
"%s %d", token, &MinElementSize)==0)
return(-1);
94 if(fgets(line, lineLength, handle)==0)
return(-1);
95 if(fgets(line, lineLength, handle)==0)
return(-1);
96 if(sscanf(line,
"%s %d", token, &IndexBase)==0)
return(-1);
98 if(fgets(line, lineLength, handle)==0)
return(-1);
99 if(fgets(line, lineLength, handle)==0)
return(-1);
100 if(sscanf(line,
"%s %d", token, &NumGlobalElements)==0)
return(-1);
104 if (comm.NumProc()==numProc) {
105 if(fgets(line, lineLength, handle)==0)
return(-1);
107 for (
int i=0; i<comm.MyPID(); i++) {
108 if(fgets(line, lineLength, handle)==0)
return(-1);
109 if(sscanf(line,
"%s %d", token, &NumMyElements)==0)
return(-1);
110 firstGid += NumMyElements;
113 if(fgets(line, lineLength, handle)==0)
return(-1);
114 if(sscanf(line,
"%s %d", token, &NumMyElements)==0)
return(-1);
116 for (
int i=comm.MyPID()+1; i<numProc; i++) {
117 if(fgets(line, lineLength, handle)==0)
return(-1);
123 if(fgets(line, lineLength, handle)==0)
return(-1);
124 for (
int i=0; i<numProc; i++) {
125 if(fgets(line, lineLength, handle)==0)
return(-1);
128 NumMyElements = NumGlobalElements/comm.NumProc();
129 firstGid = comm.MyPID()*NumMyElements;
130 int remainder = NumGlobalElements%comm.NumProc();
131 if (comm.MyPID()<remainder) NumMyElements++;
132 int extra = remainder;
133 if (comm.MyPID()<remainder) extra = comm.MyPID();
136 if(fgets(line, lineLength, handle)==0)
return(-1);
137 if(sscanf(line,
"%d %d", &M, &N)==0)
return(-1);
139 bool doSizes = (N>1);
140 Epetra_IntSerialDenseVector v1(NumMyElements);
141 Epetra_IntSerialDenseVector v2(NumMyElements);
142 for (
int i=0; i<firstGid; i++) {
143 if(fgets(line, lineLength, handle)==0)
return(-1);
147 for (
int i=0; i<NumMyElements; i++) {
148 if(fgets(line, lineLength, handle)==0)
return(-1);
149 if(sscanf(line,
"%d %d", &v1[i], &v2[i])==0)
return(-1);
153 for (
int i=0; i<NumMyElements; i++) {
154 if(fgets(line, lineLength, handle)==0)
return(-1);
155 if(sscanf(line,
"%d", &v1[i])==0)
return(-1);
156 v2[i] = MinElementSize;
159 if (fclose(handle))
return(-1);
163 if (MinElementSize==1 && MaxElementSize==1)
164 map =
new Epetra_Map(-1, NumMyElements, v1.Values(), IndexBase, comm);
166 map =
new Epetra_BlockMap(-1, NumMyElements, v1.Values(), v2.Values(), IndexBase, comm);
171 const Epetra_Comm& comm,
172 Epetra_BlockMap*& rowmap)
174 FILE* infile = fopen(filename,
"r");
178 if (err != 0)
return(err);
185 int numrows, numcols;
187 if (err != 0)
return(err);
191 rowmap =
new Epetra_BlockMap(numrows, 1, 0, comm);
196 const Epetra_Comm& comm,
197 Epetra_BlockMap*& rowmap,
198 Epetra_BlockMap*& colmap,
199 Epetra_BlockMap*& rangemap,
200 Epetra_BlockMap*& domainmap)
202 FILE* infile = fopen(filename,
"r");
203 if (infile == NULL) {
210 if (err != 0)
return(err);
217 int numrows, numcols, nnz;
219 if (err != 0)
return(err);
225 rowmap =
new Epetra_BlockMap(numrows, 1, 0, comm);
226 rangemap =
new Epetra_BlockMap(numrows, 1, 0, comm);
231 int num_map_cols = 0, insertPoint, foundOffset;
232 int allocLen = numcols;
233 int* map_cols =
new int[allocLen];
238 for(
int i=0; i<nnz; ++i) {
245 if (rowmap->MyGID(I)) {
246 foundOffset = Epetra_Util_binary_search(J, map_cols, num_map_cols,
248 if (foundOffset < 0) {
249 Epetra_Util_insert(J, insertPoint, map_cols,
250 num_map_cols, allocLen);
258 colmap =
new Epetra_Map(-1, num_map_cols, map_cols, 0, comm);
261 domainmap =
new Epetra_BlockMap(numcols, 1, 0, comm);
int mm_read_mtx_crd_size(FILE *f, int *M, int *N, int *nz)
int mm_read_mtx_array_size(FILE *f, int *M, int *N)
EpetraExt::BlockCrsMatrix: A class for constructing a distributed block matrix.
int mm_read_banner(FILE *f, MM_typecode *matcode)
#define mm_is_coordinate(typecode)
int MatrixMarketFileToMap(const char *filename, const Epetra_Comm &comm, Epetra_Map *&map)
Constructs an Epetra_BlockMap object from a Matrix Market format file.
int MatrixMarketFileToRowMap(const char *filename, const Epetra_Comm &comm, Epetra_BlockMap *&rowmap)
#define mm_is_real(typecode)
int mm_read_mtx_crd_entry(FILE *f, int *I, int *J, double *real, double *imag, MM_typecode matcode)
#define mm_is_matrix(typecode)
#define mm_is_general(typecode)
int MatrixMarketFileToBlockMap(const char *filename, const Epetra_Comm &comm, Epetra_BlockMap *&map)
Constructs an Epetra_BlockMap object from a Matrix Market format file.
int MatrixMarketFileToBlockMaps(const char *filename, const Epetra_Comm &comm, Epetra_BlockMap *&rowmap, Epetra_BlockMap *&colmap, Epetra_BlockMap *&rangemap, Epetra_BlockMap *&domainmap)
Constructs row,col,range and domain maps from a matrix-market matrix file.