43 #include "Epetra_Comm.h"
44 #include "Epetra_Map.h"
45 #include "Epetra_Vector.h"
46 #include "Epetra_MultiVector.h"
47 #include "Epetra_IntVector.h"
48 #include "Epetra_SerialDenseVector.h"
49 #include "Epetra_IntSerialDenseVector.h"
50 #include "Epetra_Import.h"
51 #include "Epetra_CrsMatrix.h"
53 using namespace EpetraExt;
64 const char * matrixName,
65 const char *matrixDescription,
71 if (!domainMap.
UniqueGIDs()) {EPETRA_CHK_ERR(-2);}
72 if (!rangeMap.
UniqueGIDs()) {EPETRA_CHK_ERR(-2);}
74 long long M = rangeMap.NumGlobalElements64();
75 long long N = domainMap.NumGlobalElements64();
81 if (
get_nz(A, nz)) {EPETRA_CHK_ERR(-1);}
85 handle = fopen(filename,
"w");
86 if (!handle) {EPETRA_CHK_ERR(-1);}
94 if (writeHeader==
true) {
96 if (
mm_write_banner(handle, matcode)!=0) {
if (handle!=0) fclose(handle); EPETRA_CHK_ERR(-1);}
98 if (matrixName!=0) fprintf(handle,
"%% \n%% %s\n", matrixName);
99 if (matrixDescription!=0) fprintf(handle,
"%% %s\n%% \n", matrixDescription);
105 if (
OperatorToHandle(handle, A)!=0) {
if (handle!=0) fclose(handle); EPETRA_CHK_ERR(-1);}
107 if (handle!=0) fclose(handle);
115 long long N = domainMap.NumGlobalElements64();
124 long long numchunks = N/chunksize;
125 int rem = N%chunksize;
132 for (
int j=0; j<rem; j++) {
133 long long curGlobalCol = rootDomainMap.GID64(j);
134 if (domainMap.
MyGID(curGlobalCol)) {
135 int curCol = domainMap.
LID(curGlobalCol);
136 xrem[j][curCol] = 1.0;
139 EPETRA_CHK_ERR(A.
Apply(xrem, yrem));
140 EPETRA_CHK_ERR(yrem1.Import(yrem, importer,
Insert));
148 for (
long long ichunk = 0; ichunk<numchunks; ichunk++) {
149 long long startCol = ichunk*chunksize+rem;
151 for (
int j=0; j<chunksize; j++) {
152 long long curGlobalCol = rootDomainMap.GID64(startCol+j);
153 if (domainMap.
MyGID(curGlobalCol)){
154 int curCol = domainMap.
LID(curGlobalCol);
158 EPETRA_CHK_ERR(A.
Apply(x, y));
159 EPETRA_CHK_ERR(y1.Import(y, importer,
Insert));
160 EPETRA_CHK_ERR(
writeOperatorStrip(handle, y1, rootDomainMap, rootRangeMap, startCol));
162 for (
int j=0; j<chunksize; j++) {
163 long long curGlobalCol = rootDomainMap.GID64(startCol+j);
164 if (domainMap.
MyGID(curGlobalCol)){
165 int curCol = domainMap.
LID(curGlobalCol);
176 long long numRows = y.GlobalLength64();
177 int numCols = y.NumVectors();
178 long long ioffset = 1 - rootRangeMap.IndexBase64();
179 long long joffset = 1 - rootDomainMap.IndexBase64();
180 if (y.Comm().MyPID()!=0) {
181 if (y.MyLength()!=0) {EPETRA_CHK_ERR(-1);}
184 if (numRows!=y.MyLength()) {EPETRA_CHK_ERR(-1);}
185 for (
int j=0; j<numCols; j++) {
186 long long J = rootDomainMap.GID64(j + startColumn) + joffset;
187 for (
long long i=0; i<numRows; i++) {
188 double val = y[j][i];
190 long long I = rootRangeMap.GID64(i) + ioffset;
191 fprintf(handle,
"%lld %lld %22.16e\n", I, J, val);
203 long long N = domainMap.NumGlobalElements64();
209 long long numchunks = N/chunksize;
210 int rem = N%chunksize;
217 for (
int j=0; j<rem; j++) {
218 long long curGlobalCol = rootDomainMap.GID64(j);
219 if (domainMap.
MyGID(curGlobalCol)) xrem[j][domainMap.
LID(curGlobalCol)] = 1.0;
221 EPETRA_CHK_ERR(A.
Apply(xrem, yrem));
222 for (
int j=0; j<rem; j++) {
223 int mylength = yrem.MyLength();
224 for (
int i=0; i<mylength; i++)
225 if (yrem[j][i]!=0.0) lnz++;
232 for (
long long ichunk = 0; ichunk<numchunks; ichunk++) {
233 long long startCol = ichunk*chunksize+rem;
235 for (
int j=0; j<chunksize; j++) {
236 long long curGlobalCol = rootDomainMap.GID64(startCol+j);
237 if (domainMap.
MyGID(curGlobalCol)) x[j][domainMap.
LID(curGlobalCol)] = 1.0;
239 EPETRA_CHK_ERR(A.
Apply(x, y));
240 for (
int j=0; j<chunksize; j++) {
241 int mylength = y.MyLength();
242 for (
int i=0; i<mylength; i++)
243 if (y[j][i]!=0.0) lnz++;
246 for (
int j=0; j<chunksize; j++) {
247 long long curGlobalCol = rootDomainMap.GID64(startCol+j);
248 if (domainMap.
MyGID(curGlobalCol)) x[j][domainMap.
LID(curGlobalCol)] = 0.0;
254 EPETRA_CHK_ERR(A.
Comm().
SumAll(&lnz, &nz, 1));
#define mm_set_coordinate(typecode)
static Epetra_Map Create_Root_Map(const Epetra_Map &usermap, int root=0)
#define mm_set_real(typecode)
int OperatorToMatrixMarketFile(const char *filename, const Epetra_Operator &A, const char *matrixName, const char *matrixDescription, bool writeHeader)
Writes an Epetra_Operator object to a Matrix Market format file, forming the coefficients by applying...
#define mm_set_matrix(typecode)
int mm_write_banner(FILE *f, MM_typecode matcode)
virtual const Epetra_Map & OperatorDomainMap() const =0
virtual int MyPID() const =0
virtual int SumAll(double *PartialSums, double *GlobalSums, int Count) const =0
virtual int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const =0
virtual const Epetra_Map & OperatorRangeMap() const =0
int mm_write_mtx_crd_size(FILE *f, long long M, long long N, long long nz)
virtual const Epetra_Comm & Comm() const =0
int get_nz(const Epetra_Operator &A, long long &nz)
int OperatorToHandle(FILE *handle, const Epetra_Operator &A)
bool MyGID(int GID_in) const
const Epetra_Comm & Comm() const
int OperatorToMatlabFile(const char *filename, const Epetra_Operator &A)
Writes an Epetra_Operator object to a file that is compatible with Matlab.
#define mm_initialize_typecode(typecode)
int writeOperatorStrip(FILE *handle, const Epetra_MultiVector &y, const Epetra_Map &rootDomainMap, const Epetra_Map &rootRangeMap, long long startColumn)