41 #include "Epetra_ConfigDefs.h" 44 #include "Epetra_Comm.h" 45 #include "Epetra_BlockMap.h" 46 #include "Epetra_Map.h" 47 #include "Epetra_IntVector.h" 48 #include "Epetra_LongLongVector.h" 49 #include "Epetra_GIDTypeVector.h" 50 #include "Epetra_IntSerialDenseVector.h" 51 #include "Epetra_LongLongSerialDenseVector.h" 52 #include "Epetra_GIDTypeSerialDenseVector.h" 53 #include "Epetra_Import.h" 60 const char *mapDescription,
62 long long M = map.NumGlobalElements64();
64 if (map.MaxElementSize()>1)
N = 2;
68 if (map.Comm().MyPID()==0) {
71 if (!handle)
return(-1);
78 if (writeHeader==
true) {
82 if (mapName!=0) fprintf(handle,
"%% \n%% %s\n", mapName);
83 if (mapDescription!=0) fprintf(handle,
"%% %s\n%% \n", mapDescription);
88 if (writeHeader==
true) {
93 Epetra_Map map1(-1, 1, 0, map.Comm());
95 if (map.Comm().MyPID()==0) length = map.Comm().NumProc();
96 Epetra_Map map2(-1, length, 0, map.Comm());
97 Epetra_Import lengthImporter(map2, map1);
98 Epetra_IntVector v1(map1);
99 Epetra_IntVector v2(map2);
100 v1[0] = map.NumMyElements();
101 if (v2.Import(v1, lengthImporter, Insert))
return(-1);
102 if (map.Comm().MyPID()==0) {
103 fprintf(handle,
"%s",
"%Format Version:\n");
105 fprintf(handle,
"%% %d \n", map.Comm().NumProc());
106 fprintf(handle,
"%s",
"%NumProc: Number of processors:\n");
107 fprintf(handle,
"%% %d \n", map.Comm().NumProc());
108 fprintf(handle,
"%s",
"%MaxElementSize: Maximum element size:\n");
109 fprintf(handle,
"%% %d \n", map.MaxElementSize());
110 fprintf(handle,
"%s",
"%MinElementSize: Minimum element size:\n");
111 fprintf(handle,
"%% %d \n", map.MinElementSize());
112 fprintf(handle,
"%s",
"%IndexBase: Index base of map:\n");
113 fprintf(handle,
"%% %lld \n", map.IndexBase64());
114 fprintf(handle,
"%s",
"%NumGlobalElements: Total number of GIDs in map:\n");
115 fprintf(handle,
"%% %lld \n", map.NumGlobalElements64());
116 fprintf(handle,
"%s",
"%NumMyElements: BlockMap lengths per processor:\n");
117 for (
int i=0; i< v2.MyLength(); i++) fprintf(handle,
"%% %d\n", v2[i]);
124 if (map.Comm().MyPID()==0)
125 if (fclose(handle))
return(-1);
129 template<
typename int_type>
132 const Epetra_Comm & comm = map.Comm();
133 int numProc = comm.NumProc();
134 bool doSizes = !map.ConstantElementSize();
137 int_type * myElements = 0;
138 map.MyGlobalElementsPtr(myElements);
139 int * elementSizeList = 0;
140 if (doSizes) elementSizeList = map.ElementSizeList();
141 return(
writeBlockMap(handle, map.NumGlobalElements64(), myElements, elementSizeList, doSizes));
144 int numRows = map.NumMyElements();
146 Epetra_Map allGidsMap((int_type) -1, numRows, (int_type) 0,comm);
148 typename Epetra_GIDTypeVector<int_type>::impl allGids(allGidsMap);
149 for (
int i=0; i<numRows; i++) allGids[i] = (int_type) map.GID64(i);
151 Epetra_IntVector allSizes(allGidsMap);
152 for (
int i=0; i<numRows; i++) allSizes[i] = map.ElementSize(i);
155 int numChunks = numProc;
156 int stripSize = allGids.GlobalLength64()/numChunks;
157 int remainder = allGids.GlobalLength64()%numChunks;
159 int curStripSize = 0;
160 typename Epetra_GIDTypeSerialDenseVector<int_type>::impl importGidList;
161 Epetra_IntSerialDenseVector importSizeList;
162 if (comm.MyPID()==0) {
163 importGidList.Size(stripSize+1);
164 if (doSizes) importSizeList.Size(stripSize+1);
166 for (
int i=0; i<numChunks; i++) {
167 if (comm.MyPID()==0) {
168 curStripSize = stripSize;
169 if (i<remainder) curStripSize++;
170 for (
int j=0; j<curStripSize; j++) importGidList[j] = j + curStart;
171 curStart += curStripSize;
174 Epetra_Map importGidMap((int_type) -1, curStripSize, importGidList.Values(), 0, comm);
175 Epetra_Import gidImporter(importGidMap, allGidsMap);
177 typename Epetra_GIDTypeVector<int_type>::impl importGids(importGidMap);
178 if (importGids.Import(allGids, gidImporter, Insert))
return(-1);
179 Epetra_IntVector importSizes(importGidMap);
180 if (doSizes)
if (importSizes.Import(allSizes, gidImporter, Insert))
return(-1);
185 int_type * myElements = importGids.Values();
186 int * elementSizeList = 0;
187 if (doSizes) elementSizeList = importSizes.Values();
189 writeBlockMap(handle, importGids.MyLength(), myElements, elementSizeList, doSizes);
195 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES 196 if(map.GlobalIndicesInt()) {
197 return TBlockMapToHandle<int>(handle, map);
201 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES 202 if(map.GlobalIndicesLongLong()) {
203 return TBlockMapToHandle<long long>(handle, map);
207 throw "EpetraExt::BlockMapToHandle: GlobalIndices type unknown";
210 int writeBlockMap(FILE * handle,
long long length,
const int * v1,
const int * v2,
bool doSizes) {
212 for (
long long i=0; i<length; i++) {
213 fprintf(handle,
"%d", v1[i]);
214 if (doSizes) fprintf(handle,
" %d", v2[i]);
215 fprintf(handle,
"%s",
"\n");
220 int writeBlockMap(FILE * handle,
long long length,
const long long * v1,
const int * v2,
bool doSizes) {
222 for (
long long i=0; i<length; i++) {
223 fprintf(handle,
"%lld", v1[i]);
224 if (doSizes) fprintf(handle,
" %d", v2[i]);
225 fprintf(handle,
"%s",
"\n");
int writeBlockMap(FILE *handle, long long length, const int *v1, const int *v2, bool doSizes)
int BlockMapToMatrixMarketFile(const char *filename, const Epetra_BlockMap &map, const char *mapName, const char *mapDescription, bool writeHeader)
Writes an Epetra_BlockMap or Epetra_Map object to a Matrix Market format file.
#define mm_set_matrix(typecode)
int mm_write_banner(FILE *f, MM_typecode matcode)
#define mm_set_integer(typecode)
EpetraExt::BlockCrsMatrix: A class for constructing a distributed block matrix.
int BlockMapToHandle(FILE *handle, const Epetra_BlockMap &map)
int TBlockMapToHandle(FILE *handle, const Epetra_BlockMap &map)
#define mm_set_array(typecode)
int mm_write_mtx_array_size(FILE *f, long long M, long long N)
#define mm_initialize_typecode(typecode)