54 #ifndef INCLUDE_MATRIX_IO__H
55 #define INCLUDE_MATRIX_IO__H
79 for(i=0;i<xadj[Nr];i++){
87 const char * file,
int line){
92 int *rowind = *padjncy;
105 if (colptr == NULL) {
106 hit_errInternal(__FUNCTION__,
"Symmetrize: not enough memory for data structures",
"",file,line);
109 for(i=(*pNr)+1;i<N+1;i++){
110 colptr[i] = colptr[i-1];
120 (*pxadj) =
idxmalloc(N+1, (
char *)&
"Symmetrize: xadj");
121 (*padjncy) =
idxmalloc(2*nz, (
char *)&
"Symmetrize: adjncy");
130 if ((*pxadj)==NULL || (*padjncy)==NULL || n_edge==NULL) {
131 hit_errInternal(__FUNCTION__,
"Symmetrize: not enough memory for data structures",
"",file,line);
138 int begin = colptr[i]-1;
139 int end = colptr[i+1]-1;
140 for(j=begin;j<end;j++){
142 int target = rowind[j]-1;
143 int begin2 = colptr[target]-1;
144 int end2 = colptr[target+1]-1;
148 for(j2=begin2;j2<end2;j2++){
149 int target2 = rowind[j2]-1;
155 n_edge[target] += notfound;
163 int begin = colptr[i]-1;
164 int end = colptr[i+1]-1;
165 int length = (end-begin) + n_edge[i];
167 (*pxadj)[i+1] = (*pxadj)[i] + length;
173 int begin = colptr[i]-1;
174 int end = colptr[i+1]-1;
175 int length = (end-begin);
177 int newbegin = (*pxadj)[i];
179 for(j=0;j<length;j++){
181 int target = rowind[begin+j]-1;
182 (*padjncy)[newbegin+j] = target;
189 int begin = colptr[i]-1;
190 int end = colptr[i+1]-1;
191 for(j=begin;j<end;j++){
193 int target = rowind[j]-1;
194 int begin2 = colptr[target]-1;
195 int end2 = colptr[target+1]-1;
200 if(n_edge[target] == 0)
continue;
202 for(j2=begin2;j2<end2;j2++){
203 int target2 = rowind[j2]-1;
212 int pos = (*pxadj)[target+1]-n_edge[target];
223 int begin = (*pxadj)[i];
224 int end = (*pxadj)[i+1];
247 const char * file,
int line){
251 hit_warnInternal(__FUNCTION__,
"Only root processor should use this function",
"",file,line);
268 int *xadj = NULL, *adjncy = NULL;
274 read_mm_matrix ((
char *)fileName, &Nr, &Nc, &nz, &xadj, &adjncy, &val);
288 printf(
"\nMM: Nr: %d Nc: %d \n", Nr, Nc);
293 for(j=begin;j<end;j++){
294 printf(
" %d ", adjncy[j]);
341 const char * file,
int line){
345 hit_warnInternal(__FUNCTION__,
"Only root processor should use this function",
"",file,line);
360 if( !
readHB_info(fileName, &Nr, &Nc, &nz, &type, &Nrhs) ) {
361 hit_errInternal(__FUNCTION__,
"Reading Harwell-Boeing file header",
"",file,line);
366 fprintf(stderr,
"[HB file] Nr: %d, Nc: %d, nz: %d, type: %s, Nrhs: %d\n",Nr,Nc,nz,type,Nrhs);
372 hit_warnInternal(__FUNCTION__,
"Hitmap ignores Harwell-Boeing matrices with right-hand-sides",
"",file,line);
377 if( type[0] !=
'P' ){
378 hit_warnInternal(__FUNCTION__,
"Hitmap ignores Harwell-Boeing matrix values",
"",file,line);
382 if( type[1] !=
'U' && type[1] !=
'R' && type[1] !=
'S' ){
383 hit_errInternal(__FUNCTION__,
"Harwell-Boeing matrix type not supported",
"",file,line);
388 if( type[2] !=
'A' ){
389 hit_errInternal(__FUNCTION__,
"Harwell-Boeing matrix is not assembled",
"",file,line);
398 int *xadj = NULL, *adjncy = NULL;
404 hit_errInternal(__FUNCTION__,
"Reading Harwell-Boeing matrix data",
"",file,line);
410 if(type[1] ==
'S' || create_graph){
419 printf(
"\nHB: Nr: %d Nc: %d \n", Nr, Nc);
424 for(j=begin;j<end;j++){
425 printf(
" %d ", adjncy[j]);
467 const char * file,
int line){
471 hit_warnInternal(__FUNCTION__,
"Only root processor should use this function",
"",file,line);
486 if( !
readHB_info(fileName, &Nr, &Nc, &nz, &type, &Nrhs) ) {
487 hit_errInternal(__FUNCTION__,
"Reading Harwell-Boeing file header",
"",file,line);
492 fprintf(stderr,
"[HB file] Nr: %d, Nc: %d, nz: %d, type: %s, Nrhs: %d\n",Nr,Nc,nz,type,Nrhs);
498 hit_warnInternal(__FUNCTION__,
"Hitmap ignores Harwell-Boeing matrices with right-hand-sides",
"",file,line);
503 if( type[0] !=
'P' ){
504 hit_warnInternal(__FUNCTION__,
"Hitmap ignores Harwell-Boeing matrix values",
"",file,line);
508 if( type[1] !=
'U' && type[1] !=
'R' && type[1] !=
'S' ){
509 hit_errInternal(__FUNCTION__,
"Harwell-Boeing matrix type not supported",
"",file,line);
514 if( type[2] !=
'A' ){
515 hit_errInternal(__FUNCTION__,
"Harwell-Boeing matrix is not assembled",
"",file,line);
524 int *xadj = NULL, *adjncy = NULL;
530 hit_errInternal(__FUNCTION__,
"Reading Harwell-Boeing matrix data",
"",file,line);
548 for(i=0; i<Nr; i++) {
549 int cstyleIni = xadj[i]-1;
550 int cstyleEnd = xadj[i+1]-1;
552 for(j=cstyleIni; j<cstyleEnd; j++) {
554 if(type[1] ==
'S' || create_graph){
577 #define NUMBERS_LINE 10
578 #define NUMBERS_SIZE 8
586 FILE * file = fopen(hbfile,
"w");
594 fprintf(file,
"%-72s",
"HitMap HB Export");
596 fprintf(file,
"%-8s",
"key");
603 int ptrcrd = (int) ceil(((
double) nvertices + 1) /
NUMBERS_LINE );
604 int indcrd = (int) ceil((
double) nedges /
NUMBERS_LINE );
605 fprintf(file,
"%14d",ptrcrd + indcrd);
606 fprintf(file,
"%14d",ptrcrd);
607 fprintf(file,
"%14d",indcrd);
610 fprintf(file,
"%14d",0);
611 fprintf(file,
"%14s",
"");
617 fprintf(file,
"%3s",
"pua");
619 fprintf(file,
"%11s",
"");
621 fprintf(file,
"%14d", nvertices);
623 fprintf(file,
"%14d", nvertices);
625 fprintf(file,
"%14d", nedges);
627 fprintf(file,
"%14d", 0);
633 fprintf(file,
"%-16s",
"(10I8)");
635 fprintf(file,
"%-16s",
"(10I8)");
637 fprintf(file,
"%-20s",
"");
639 fprintf(file,
"%-20s",
"");
644 for(i=0;i<=nvertices;i++){
648 fprintf(file,
"%8d",vertex+1);
652 for(i=0;i<nedges;i++){
656 fprintf(file,
"%8d",edge+1);
668 #define NUMBERS_LINE 10
669 #define NUMBERS_SIZE 8
677 FILE * file = fopen(hbfile,
"w");
686 fprintf(file,
"%-72s",
"HitMap HB Export");
688 fprintf(file,
"%-8s",
"key");
695 int ptrcrd = (int) ceil(((
double) nvertices + 1) /
NUMBERS_LINE );
696 int indcrd = (int) ceil((
double) nedges /
NUMBERS_LINE );
697 fprintf(file,
"%14d",ptrcrd + indcrd);
698 fprintf(file,
"%14d",ptrcrd);
699 fprintf(file,
"%14d",indcrd);
702 fprintf(file,
"%14d",0);
703 fprintf(file,
"%14s",
"");
709 fprintf(file,
"%3s",
"pua");
711 fprintf(file,
"%11s",
"");
713 fprintf(file,
"%14d", nvertices);
715 fprintf(file,
"%14d", nvertices);
717 fprintf(file,
"%14d", nedges);
719 fprintf(file,
"%14d", 0);
725 fprintf(file,
"%-16s",
"(10I8)");
727 fprintf(file,
"%-16s",
"(10I8)");
729 fprintf(file,
"%-20s",
"");
731 fprintf(file,
"%-20s",
"");
740 fprintf(file,
"%8d",indexId+1);
749 fprintf(file,
"%8d",indexId+1);
762 fprintf(file,
"%8d",target+1);
782 hit_warnInternal(__FUNCTION__,
"Only root processor should use this function",
"",file,line);
797 if( !
readHB_info(hbfile, &M, &N, &nz, &type, &Nrhs) ) {
798 hit_errInternal(__FUNCTION__,
"Reading Harwell-Boeing file header",
"",file,line);
804 hit_errInternal(__FUNCTION__,
"Recognized Harwell-Boeing matrices must be square",
"",file,line);
820 hit_warnInternal(__FUNCTION__,
"Only root processor should use this function",
"",file,line);
829 HitTile_int *tile = (HitTile_int *)tileP;
831 hit_errInternal(__FUNCTION__,
"The tile must be allocated",
"",file,line);
846 if( !
readHB_info(fileName, &M, &N, &nz, &type, &Nrhs) ) {
847 hit_errInternal(__FUNCTION__,
"Reading Harwell-Boeing file header",
"",file,line);
852 fprintf(stderr,
"DATOS: M: %d, N: %d, nz: %d, type: %s, Nrhs: %d\n",M,N,nz,type,Nrhs);
857 hit_errInternal(__FUNCTION__,
"Recognized Harwell-Boeing files must not have RHS",
"",file,line);
863 hit_errInternal(__FUNCTION__,
"Recognized Harwell-Boeing matrices must be square",
"",file,line);
875 int *colptr = NULL, *rowind = NULL;
882 hit_errInternal(__FUNCTION__,
"Reading Harwell-Boeing matrix data",
"",file,line);
899 int begin = colptr[i]-1;
900 int end = colptr[i+1]-1;
901 for(j=begin;j<end;j++){
902 printf(
" %d ", rowind[j]-1);
918 int cstyleIni = colptr[i]-1;
919 int cstyleEnd = colptr[i+1]-1;
921 for(j=cstyleIni; j<cstyleEnd; j++) {
923 hit_tileElemAt2(*tile,i,rowind[j]-1) = 1;
924 hit_tileElemAt2(*tile,rowind[j]-1,i) = 1;
946 hit_warnInternal(__FUNCTION__,
"Only root processor should use this function",
"",cfile,line);
950 FILE * file = fopen(csrfile,
"r");
957 char c = (char) getc(file);
960 if(c ==
'#' || c ==
' ' || c ==
'\n'){
961 while( c !=
'\n' ) c = (char) getc(file);
966 c = (char) getc(file);
971 r = fscanf(file,
"%d\n",&n);
972 if(r != 1)
hit_errInternal(__func__,
"Error reading CSR format",
"", __FILE__, __LINE__ );
983 if(r != 1)
hit_errInternal(__func__,
"Error reading CSR format",
"", __FILE__, __LINE__ );
991 for(i=0;i<nedges;i++){
993 if(r != 1)
hit_errInternal(__func__,
"Error reading CSR format",
"", __FILE__, __LINE__ );
1012 hit_warnInternal(__FUNCTION__,
"Only root processor should use this function",
"",cfile,line);
1016 FILE * file = fopen(csrfile,
"w");
1017 if(file == NULL)
return;
1020 fprintf(file,
"# CSR graph generated by the Hitmap library\n");
1021 fprintf(file,
"# Format:\n");
1022 fprintf(file,
"# - Number of vertices.\n");
1023 fprintf(file,
"# - Xadj list.\n");
1024 fprintf(file,
"# - Adjncy list.\n");
1025 fprintf(file,
"# - Vertices name list.\n\n");
1030 fprintf(file,
"%d\n",n);
1041 for(i=0;i<nedges;i++){
#define hit_bShapeSet(bitshape, i, j)
#define hit_cShapeAdjncy(shape)
void hit_csr_renameIndexes(int Nr, int *xadj, int *adjncy)
#define hit_tileNewType(baseType)
#define hit_cShapeNedges(shape)
#define hit_tileFill(var, value)
int hit_csr_renameIndexes_and_Symmetrize(int *pNr, int *pNc, int nz, int **pxadj, int **padjncy, const char *file, int line)
#define hit_bShapeEdgeTarget(s, edge)
#define hit_bShapeEdgeIterator(var, shape, vertex)
#define hit_calloc(ptr, type, nmemb)
HitShape hit_bitmapShape(int nvertices)
#define hit_cShapeCard(shape, dim)
void hit_fileHBWriteBitmapInternal(const char *hbfile, HitShape shape, int rank, const char *file, int line)
void hit_nameListCreate(HitNameList *list, int nelems)
#define hit_bShapeVertexIterator(var, shape)
#define hit_bShapeNedges(shape)
#define hit_cShapeXadj(shape)
int hit_fileHBReadDenseInternal(const char *hbfile, int rank, void *tileP, const char *file, int line)
#define hit_cShapeNvertices(shape)
Hitmap functions to allocate memory.
int readHB_newmat_double(const char *filename, int *M, int *N, int *nonzeros, int **colptr, int **rowind, double **val)
#define hit_cShapeNameList(shape, dim)
#define hit_malloc(ptr, type, nmemb)
void hit_fileCSRWriteInternal(const char *csrfile, HitShape shape, int rank, const char *cfile, int line)
HitShape hit_bitmapShapeMatrix(int n, int m)
#define hit_bShapeNvertices(shape)
HitShape hit_fileHBRead_toBitmap_Internal(const char *fileName, int create_graph, int rank, const char *file, int line)
HitShape hit_fileMMRead_toCSR_Internal(const char *fileName, int create_graph, int rank, const char *file, int line)
void read_mm_matrix(char *fn, int *m, int *n, int *nz, int **i_idx, int **j_idx, double **a)
HitShape HIT_CSR_SHAPE_NULL
#define hit_tileIsNull(var)
HitShape hit_fileCSRReadInternal(const char *csrfile, int rank, const char *cfile, int line)
HitShape HIT_BITMAP_SHAPE_NULL
#define hit_realloc(ptr, type, nmemb)
int compare_idxtype(const void *a, const void *b)
HitShape hit_fileHBRead_toCSR_Internal(const char *fileName, int create_graph, int rank, const char *file, int line)
int readHB_info(const char *filename, int *M, int *N, int *nz, char **Type, int *Nrhs)
int hit_fileHBVerticesInternal(const char *hbfile, int rank, const char *file, int line)
#define hit_warnInternal(routine, text, extraParam, file, numLine)
#define hit_errInternal(routine, text, extraParam, file, numLine)
void hit_fileHBWriteInternal(const char *hbfile, HitShape shape, int rank, const char *file, int line)