57 using namespace EpetraExt;
62 std::FILE * handle = 0;
64 handle = fopen(filename,
"w");
65 if (!handle)
return(-1);
70 if (fclose(handle))
return(-1);
75 const char * matrixName,
76 const char *matrixDescription,
78 long long M = A.GlobalLength64();
79 int N = A.NumVectors();
85 handle = fopen(filename,
"w");
86 if (!handle)
return(-1);
93 if (writeHeader==
true) {
97 if (matrixName!=0) fprintf(handle,
"%% \n%% %s\n", matrixName);
98 if (matrixDescription!=0) fprintf(handle,
"%% %s\n%% \n", matrixDescription);
107 if (fclose(handle))
return(-1);
118 template<
typename int_type>
133 if (A.NumVectors()>1 && mmFormat) {
134 for (
int i=0; i<A.NumVectors(); i++)
144 Epetra_Map allGidsMap((int_type) -1, numRows, (int_type) 0,comm);
147 for (
int i=0; i<numRows; i++) allGids[i] = (int_type) map.
GID64(i);
150 int numChunks = numProc;
151 int stripSize = allGids.GlobalLength64()/numChunks;
152 int remainder = allGids.GlobalLength64()%numChunks;
154 int curStripSize = 0;
157 importGidList.Size(stripSize+1);
158 for (
int i=0; i<numChunks; i++) {
159 if (comm.
MyPID()==0) {
160 curStripSize = stripSize;
161 if (i<remainder) curStripSize++;
162 for (
int j=0; j<curStripSize; j++) importGidList[j] = j + curStart;
163 curStart += curStripSize;
166 Epetra_Map importGidMap((int_type) -1, curStripSize, importGidList.Values(), (int_type) 0, comm);
169 if (importGids.Import(allGids, gidImporter,
Insert))
return(-1);
175 Epetra_Map importMap((int_type) -1, importGids.MyLength(), importGids.Values(), (int_type) 0, comm);
178 if (importA.Import(A1, importer,
Insert))
return(-1);
188 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
190 return TMultiVectorToHandle<int>(handle, A, mmFormat);
194 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
196 return TMultiVectorToHandle<long long>(handle, A, mmFormat);
200 throw "EpetraExt::MultiVectorToHandle: GlobalIndices type unknown";
206 long long length = A.GlobalLength64();
207 int numVectors = A.NumVectors();
209 if (comm.
MyPID()!=0) {
210 if (A.MyLength()!=0) ierr = -1;
213 if (length!=A.MyLength()) ierr = -1;
214 for (
int j=0; j<numVectors; j++) {
215 for (
long long i=0; i<length; i++) {
216 double val = A[j][i];
218 fprintf(handle,
"%22.16e\n", val);
220 fprintf(handle,
"%22.16e ", val);
222 if (!mmFormat) fprintf(handle,
"%s",
"\n");
226 comm.
MinAll(&ierr, &ierrGlobal, 1);
#define mm_set_real(typecode)
bool GlobalIndicesLongLong() const
int MultiVectorToMatlabFile(const char *filename, const Epetra_MultiVector &A)
Writes an Epetra_MultiVector object to a file that is compatible with Matlab.
#define mm_set_matrix(typecode)
int mm_write_banner(FILE *f, MM_typecode matcode)
bool GlobalIndicesInt() const
virtual int MinAll(double *PartialMins, double *GlobalMins, int Count) const =0
int MultiVectorToMatlabHandle(FILE *handle, const Epetra_MultiVector &A)
virtual int MyPID() const =0
int NumMyElements() const
long long GID64(int LID) const
virtual const Epetra_BlockMap & Map() const =0
int MultiVectorToMatrixMarketFile(const char *filename, const Epetra_MultiVector &A, const char *matrixName, const char *matrixDescription, bool writeHeader)
Writes an Epetra_MultiVector object to a Matrix Market format file.
const Epetra_Comm & Comm() const
int writeMultiVector(FILE *handle, const Epetra_MultiVector &A, bool mmFormat)
virtual int NumProc() const =0
#define mm_set_array(typecode)
int TMultiVectorToHandle(FILE *handle, const Epetra_MultiVector &A, bool mmFormat)
int mm_write_mtx_array_size(FILE *f, long long M, long long N)
int MultiVectorToHandle(FILE *handle, const Epetra_MultiVector &A, bool mmFormat)
#define mm_initialize_typecode(typecode)
int MultiVectorToMatrixMarketHandle(FILE *handle, const Epetra_MultiVector &A)