57 using namespace EpetraExt;
67 const char * matrixName,
68 const char *matrixDescription,
78 handle = fopen(filename,
"w");
86 if (writeHeader==
true) {
90 if (matrixName!=0) fprintf(handle,
"%% \n%% %s\n", matrixName);
91 if (matrixDescription!=0) fprintf(handle,
"%% %s\n%% \n", matrixDescription);
104 template<
typename int_type>
116 Epetra_Map allGidsMap((int_type) -1, numRows, (int_type) 0,comm);
119 for (
int i=0; i<numRows; i++) allGids[i] = (int_type) map.
GID64(i);
122 int numChunks = numProc;
123 int stripSize = allGids.GlobalLength64()/numChunks;
124 int remainder = allGids.GlobalLength64()%numChunks;
126 int curStripSize = 0;
129 importGidList.Size(stripSize+1);
130 for (
int i=0; i<numChunks; i++) {
131 if (comm.
MyPID()==0) {
132 curStripSize = stripSize;
133 if (i<remainder) curStripSize++;
134 for (
int j=0; j<curStripSize; j++) importGidList[j] = j + curStart;
135 curStart += curStripSize;
138 if (comm.
MyPID()>0) assert(curStripSize==0);
139 Epetra_Map importGidMap(-1, curStripSize, importGidList.Values(), 0, comm);
162 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
164 return RowMatrixToHandle<int>(handle, A);
168 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
170 return RowMatrixToHandle<long long>(handle, A);
174 throw "EpetraExt::RowMatrixToHandle: GlobalIndices type unknown";
180 if(numRows_LL > std::numeric_limits<int>::max())
181 throw "EpetraExt::writeRowMatrix: numRows_LL > std::numeric_limits<int>::max()";
183 int numRows =
static_cast<int>(numRows_LL);
189 if (comm.
MyPID()!=0) {
197 for (
int i=0; i<numRows; i++) {
198 long long I = rowMap.
GID64(i) + ioffset;
202 for (
int j=0; j<numEntries; j++) {
203 long long J = colMap.
GID64(indices[j]) + joffset;
204 double val = values[j];
205 fprintf(handle,
"%lld %lld %22.16e\n", I, J, val);
int RowMatrixToHandle(FILE *handle, const Epetra_RowMatrix &A)
bool DistributedGlobal() const
#define mm_set_coordinate(typecode)
virtual const Epetra_Map & RowMatrixRowMap() const =0
#define mm_set_real(typecode)
bool GlobalIndicesLongLong() const
long long IndexBase64() const
#define mm_set_matrix(typecode)
int mm_write_banner(FILE *f, MM_typecode matcode)
#define EPETRA_CHK_ERR(a)
virtual const Epetra_Map & OperatorDomainMap() const =0
bool GlobalIndicesInt() const
virtual int MyPID() const =0
int FillComplete(bool OptimizeDataStorage=true)
virtual int NumMyCols() const =0
int NumMyElements() const
virtual int MaxNumEntries() const =0
int mm_write_mtx_crd_size(FILE *f, long long M, long long N, long long nz)
long long GID64(int LID) const
int RowMatrixToMatlabFile(const char *filename, const Epetra_RowMatrix &A)
Writes an Epetra_RowMatrix object to a file that is compatible with Matlab.
virtual const Epetra_BlockMap & Map() const =0
virtual int NumMyRows() const =0
virtual long long NumGlobalCols64() const =0
const Epetra_Comm & Comm() const
int writeRowMatrix(FILE *handle, const Epetra_RowMatrix &A)
virtual long long NumGlobalNonzeros64() const =0
int RowMatrixToMatrixMarketFile(const char *filename, const Epetra_RowMatrix &A, const char *matrixName, const char *matrixDescription, bool writeHeader)
Writes an Epetra_RowMatrix object to a Matrix Market format file.
virtual int NumProc() const =0
virtual int ExtractMyRowCopy(int MyRow, int Length, int &NumEntries, double *Values, int *Indices) const =0
virtual const Epetra_Map & RowMatrixColMap() const =0
#define mm_initialize_typecode(typecode)
virtual long long NumGlobalRows64() const =0