int mm_read_mtx_crd(char *fname, int *M, int *N, int *nz, int **I, int **J, double **val, MM_typecode *matcode) { int ret_code; ZOLTAN_FILE* f; if ((f = ZOLTAN_FILE_open(fname, "r", STANDARD)) == NULL) return MM_COULD_NOT_READ_FILE; if ((ret_code = mm_read_banner(f, matcode)) != 0) return ret_code; if (!(mm_is_valid(*matcode) && mm_is_sparse(*matcode) && mm_is_matrix(*matcode))) return MM_UNSUPPORTED_TYPE; if ((ret_code = mm_read_mtx_crd_size(f, M, N, nz)) != 0) return ret_code; *I = (int *) malloc(*nz * sizeof(int)); *J = (int *) malloc(*nz * sizeof(int)); *val = NULL; if (mm_is_complex(*matcode)) { *val = (double *) malloc(*nz * 2 * sizeof(double)); ret_code = mm_read_mtx_crd_data(f, *M, *N, *nz, *I, *J, *val, *matcode); if (ret_code != 0) return ret_code; } else if (mm_is_real(*matcode)) { *val = (double *) malloc(*nz * sizeof(double)); ret_code = mm_read_mtx_crd_data(f, *M, *N, *nz, *I, *J, *val, *matcode); if (ret_code != 0) return ret_code; } else if (mm_is_pattern(*matcode)) { ret_code = mm_read_mtx_crd_data(f, *M, *N, *nz, *I, *J, *val, *matcode); if (ret_code != 0) return ret_code; } ZOLTAN_FILE_close(f); return 0; }
int chaco_input_graph( ZOLTAN_FILE *fin, /* input file */ char *inname, /* name of input file */ int **start, /* start of edge list for each vertex */ int **adjacency, /* edge list data */ int *nvtxs, /* number of vertices in graph */ int *vwgt_dim, /* # of vertex weights per node */ float **vweights, /* vertex weight list data */ int *ewgt_dim, /* # of edge weights per edge */ float **eweights /* edge weight list data */ ) { const char *yo = "chaco_input_graph"; int *adjptr; /* loops through adjacency data */ float *ewptr; /* loops through edge weight data */ int narcs; /* number of edges expected in graph */ int nedges; /* twice number of edges really in graph */ int nedge; /* loops through edges for each vertex */ int flag; /* condition indicator */ int found_flag; /* is vertex found in adjacency list? */ int skip_flag; /* should this edge be ignored? */ int end_flag; /* indicates end of line or file */ int vtx; /* vertex in graph */ int line_num; /* line number in input file */ int sum_edges; /* total number of edges read so far */ int option = 0; /* input option */ int using_ewgts; /* are edge weights in input file? */ int using_vwgts; /* are vertex weights in input file? */ int vtxnums; /* are vertex numbers in input file? */ int vertex; /* current vertex being read */ int new_vertex; /* new vertex being read */ float weight; /* weight being read */ float eweight; /* edge weight being read */ int neighbor; /* neighbor of current vertex */ int self_edge; /* is a self edge encountered? */ int ignore_me; /* is this edge being ignored? */ int ignored; /* how many edges are ignored? */ int error_flag; /* error reading input? */ int j; /* loop counters */ DEBUG_TRACE_START(0, yo); /* Read first line of input (= nvtxs, narcs, option). */ /* The (decimal) digits of the option variable mean: 1's digit not zero => input edge weights 10's digit not zero => input vertex weights 100's digit not zero => include vertex numbers */ *start = NULL; *adjacency = NULL; *vweights = NULL; *eweights = NULL; error_flag = 0; line_num = 0; /* Read any leading comment lines */ end_flag = 1; while (end_flag == 1) { *nvtxs = read_int(fin, &end_flag); ++line_num; } if (*nvtxs <= 0) { printf("ERROR in graph file `%s':", inname); printf(" Invalid number of vertices (%d).\n", *nvtxs); ZOLTAN_FILE_close(fin); return(1); } narcs = read_int(fin, &end_flag); if (narcs < 0) { printf("ERROR in graph file `%s':", inname); printf(" Invalid number of expected edges (%d).\n", narcs); ZOLTAN_FILE_close(fin); return(1); } /* Check if vertex or edge weights are used */ if (!end_flag) { option = read_int(fin, &end_flag); } using_ewgts = option - 10 * (option / 10); option /= 10; using_vwgts = option - 10 * (option / 10); option /= 10; vtxnums = option - 10 * (option / 10); /* Get weight dimensions from Chaco option */ (*vwgt_dim) = using_vwgts; (*ewgt_dim) = using_ewgts; /* Read weight dimensions if they are specified separately */ if (!end_flag && using_vwgts==1){ j = read_int(fin, &end_flag); if (!end_flag) (*vwgt_dim) = j; } if (!end_flag && using_ewgts==1){ j = read_int(fin, &end_flag); if (!end_flag) (*ewgt_dim) = j; } /* Discard rest of line */ while (!end_flag) j = read_int(fin, &end_flag); /* Allocate space for rows and columns. */ *start = (int *) malloc((unsigned) (*nvtxs + 1) * sizeof(int)); if (narcs != 0) *adjacency = (int *) malloc((unsigned) (2 * narcs + 1) * sizeof(int)); else *adjacency = NULL; if (using_vwgts) *vweights = (float *) malloc((unsigned) (*nvtxs) * (*vwgt_dim) * sizeof(float)); else *vweights = NULL; if (using_ewgts) *eweights = (float *) malloc((unsigned) (2 * narcs + 1) * (*ewgt_dim) * sizeof(float)); else *eweights = NULL; adjptr = *adjacency; ewptr = *eweights; self_edge = 0; ignored = 0; sum_edges = 0; nedges = 0; (*start)[0] = 0; vertex = 0; vtx = 0; new_vertex = TRUE; while ((using_vwgts || vtxnums || narcs) && end_flag != -1) { ++line_num; /* If multiple input lines per vertex, read vertex number. */ if (vtxnums) { j = read_int(fin, &end_flag); if (end_flag) { if (vertex == *nvtxs) break; printf("ERROR in graph file `%s':", inname); printf(" no vertex number in line %d.\n", line_num); ZOLTAN_FILE_close(fin); return (1); } if (j != vertex && j != vertex + 1) { printf("ERROR in graph file `%s':", inname); printf(" out-of-order vertex number in line %d.\n", line_num); ZOLTAN_FILE_close(fin); return (1); } if (j != vertex) { new_vertex = TRUE; vertex = j; } else new_vertex = FALSE; } else vertex = ++vtx; if (vertex > *nvtxs) break; /* If vertices are weighted, read vertex weight. */ if (using_vwgts && new_vertex) { for (j=0; j<(*vwgt_dim); j++){ weight = read_val(fin, &end_flag); if (end_flag) { printf("ERROR in graph file `%s':", inname); printf(" not enough weights for vertex %d.\n", vertex); ZOLTAN_FILE_close(fin); return (1); } if ((weight < 0) && Debug_Chaco_Input) { printf("ERROR in graph file `%s':", inname); printf(" negative weight entered for vertex %d.\n", vertex); ZOLTAN_FILE_close(fin); return (1); } (*vweights)[(vertex-1)*(*vwgt_dim)+j] = weight; } } nedge = 0; /* Read number of adjacent vertex. */ neighbor = read_int(fin, &end_flag); while (!end_flag) { skip_flag = FALSE; ignore_me = FALSE; if (Debug_Chaco_Input){ if (neighbor > *nvtxs) { printf("ERROR in graph file `%s':", inname); printf(" nvtxs=%d, but edge (%d,%d) was input.\n", *nvtxs, vertex, neighbor); ZOLTAN_FILE_close(fin); return (1); } if (neighbor < 0) { printf("ERROR in graph file `%s':", inname); printf(" negative vertex in edge (%d,%d).\n", vertex, neighbor); ZOLTAN_FILE_close(fin); return (1); } if (neighbor == vertex) { if (!self_edge && Debug_Chaco_Input) { printf("WARNING: Self edge (%d, %d) being ignored.\n", vertex, vertex); } skip_flag = TRUE; ++self_edge; } /* Check if adjacency is repeated. */ if (!skip_flag) { found_flag = FALSE; for (j = (*start)[vertex - 1]; !found_flag && j < sum_edges + nedge; j++) { if ((*adjacency)[j] == neighbor) found_flag = TRUE; } if (found_flag) { printf("WARNING: Multiple occurences of edge (%d,%d) ignored\n", vertex, neighbor); skip_flag = TRUE; if (!ignore_me) { ignore_me = TRUE; ++ignored; } } } } if (using_ewgts) { /* Read edge weight if it's being input. */ for (j=0; j<(*ewgt_dim); j++){ eweight = read_val(fin, &end_flag); if (end_flag) { printf("ERROR in graph file `%s':", inname); printf(" not enough weights for edge (%d,%d).\n", vertex, neighbor); ZOLTAN_FILE_close(fin); return (1); } if (eweight <= 0 && Debug_Chaco_Input) { printf("WARNING: Bad weight entered for edge (%d,%d). Edge ignored.\n", vertex, neighbor); skip_flag = TRUE; if (!ignore_me) { ignore_me = TRUE; ++ignored; } } else { *ewptr++ = eweight; } } } if (Debug_Chaco_Input){ /* Check for edge only entered once. */ if (neighbor < vertex && !skip_flag) { found_flag = FALSE; for (j = (*start)[neighbor - 1]; !found_flag && j < (*start)[neighbor]; j++) { if ((*adjacency)[j] == vertex) found_flag = TRUE; } if (!found_flag) { printf("ERROR in graph file `%s':", inname); printf(" Edge (%d, %d) entered but not (%d, %d)\n", vertex, neighbor, neighbor, vertex); error_flag = 1; } } } /* Add edge to data structure. */ if (!skip_flag) { if (++nedges > 2*narcs) { printf("ERROR in graph file `%s':", inname); printf(" at least %d adjacencies entered, but nedges = %d\n", nedges, narcs); ZOLTAN_FILE_close(fin); return (1); } *adjptr++ = neighbor; nedge++; } /* Read number of next adjacent vertex. */ neighbor = read_int(fin, &end_flag); } sum_edges += nedge; (*start)[vertex] = sum_edges; } /* Make sure there's nothing else in file. */ flag = FALSE; while (!flag && end_flag != -1) { read_int(fin, &end_flag); if (!end_flag) flag = TRUE; } if (flag && Debug_Chaco_Input) { printf("WARNING: Possible error in graph file `%s'\n", inname); printf(" Data found after expected end of file\n"); } (*start)[*nvtxs] = sum_edges; if (self_edge > 1 && Debug_Chaco_Input) { printf("WARNING: %d self edges were read and ignored.\n", self_edge); } if (vertex != 0) { /* Normal file was read. */ /* Make sure narcs was reasonable. */ if (nedges + 2 * self_edge != 2 * narcs && nedges + 2 * self_edge + ignored != 2 * narcs && nedges + self_edge != 2 * narcs && nedges + self_edge + ignored != 2 * narcs && nedges != 2 * narcs && nedges + ignored != 2 * narcs && Debug_Chaco_Input) { printf("WARNING: I expected %d edges entered twice, but I only count %d.\n", narcs, nedges); } } else { /* Graph was empty */ free(*start); if (*adjacency != NULL) free(*adjacency); if (*vweights != NULL) free(*vweights); if (*eweights != NULL) free(*eweights); *start = NULL; *adjacency = NULL; } ZOLTAN_FILE_close(fin); DEBUG_TRACE_END(0, yo); return (error_flag); }
static int input_assign_normal( ZOLTAN_FILE* finassign, /* input assignment file */ char *inassignname, /* name of input assignment file */ int nvtxs, /* number of vertices to output */ short *assignment) /* values to be printed */ { const char *yo = "input_assign_normal"; int flag; /* logical conditional */ int end_flag; /* return flag from read_int() */ int i, j; /* loop counter */ DEBUG_TRACE_START(0, yo); /* Get the assignment vector one line at a time, checking as you go. */ /* First read past any comments at top. */ end_flag = 1; while (end_flag == 1) { assignment[0] = read_int(finassign, &end_flag); } if (assignment[0] < 0) { printf("ERROR: Entry %d in assignment file `%s' less than zero (%d)\n", 1, inassignname, assignment[0]); ZOLTAN_FILE_close(finassign); DEBUG_TRACE_END(0, yo); return (1); } if (end_flag == -1) { printf("ERROR: No values found in assignment file `%s'\n", inassignname); ZOLTAN_FILE_close(finassign); DEBUG_TRACE_END(0, yo); return (1); } flag = 0; if (assignment[0] > nvtxs) flag = assignment[1]; for (i = 1; i < nvtxs; i++) { j = ZOLTAN_FILE_scanf(finassign, "%hd", &(assignment[i])); if (j != 1) { printf("ERROR: Too few values in assignment file `%s'.\n", inassignname); ZOLTAN_FILE_close(finassign); DEBUG_TRACE_END(0, yo); return (1); } if (assignment[i] < 0) { printf("ERROR: Entry %d in assignment file `%s' less than zero (%d)\n", i+1, inassignname, assignment[i]); ZOLTAN_FILE_close(finassign); DEBUG_TRACE_END(0, yo); return (1); } if (assignment[i] > nvtxs) { /* warn since probably an error */ if (assignment[i] > flag) flag = assignment[i]; } } if (flag && Debug_Chaco_Input) { printf("WARNING: Possible error in assignment file `%s'\n", inassignname); printf(" More assignment sets (%d) than vertices (%d)\n", flag, nvtxs); } /* Check for spurious extra stuff in file. */ flag = FALSE; end_flag = 0; while (!flag && end_flag != -1) { read_int(finassign, &end_flag); if (!end_flag) flag = TRUE; } if (flag && Debug_Chaco_Input) { printf("WARNING: Possible error in assignment file `%s'\n", inassignname); printf(" Numerical data found after expected end of file\n"); } ZOLTAN_FILE_close(finassign); DEBUG_TRACE_END(0, yo); return (0); }
static int input_assign_inv( ZOLTAN_FILE* finassign, /* input assignment file */ char *inassignname, /* name of input assignment file */ int nvtxs, /* number of vertices to output */ short *assignment) /* values to be printed */ { const char *yo = "input_assign_inv"; int set; /* set number being read */ int size; /* number of vertices in set */ int total; /* total number of vertices read */ int done; /* have I hit end of file yet? */ int end_flag; /* return flag from read_int() */ int i, j, k; /* loop counter */ DEBUG_TRACE_START(0, yo); /* Get the assignment vector one line at a time, checking as you go. */ /* Initialize assignment to help error detection. */ for (i = 0; i < nvtxs; i++) { assignment[i] = -1; } /* First read past any comments at top. */ total = 0; set = 0; end_flag = 1; while (end_flag == 1) { size = read_int(finassign, &end_flag); } if (end_flag == -1) { printf("ERROR: In assignment file `%s'\n", inassignname); printf(" No values found\n"); ZOLTAN_FILE_close(finassign); DEBUG_TRACE_END(0, yo); return (1); } if (size < 0) { printf("ERROR: In assignment file `%s'\n", inassignname); printf(" Size of set %d less than zero (%d)\n", set, size); ZOLTAN_FILE_close(finassign); DEBUG_TRACE_END(0, yo); return (1); } if (total + size > nvtxs) { printf("ERROR: In assignment file `%s'\n", inassignname); printf(" Total set sizes greater than nvtxs (%d)\n", nvtxs); ZOLTAN_FILE_close(finassign); DEBUG_TRACE_END(0, yo); return (1); } done = FALSE; while (!done && total < nvtxs) { for (i = 1; i <= size; i++) { j = ZOLTAN_FILE_scanf(finassign, "%d", &k); if (j != 1) { printf("ERROR: Too few values in assignment file `%s'.\n", inassignname); ZOLTAN_FILE_close(finassign); DEBUG_TRACE_END(0, yo); return (1); } if (k <= 0 || k > nvtxs) { printf("ERROR: In assignment file `%s'\n", inassignname); printf(" Entry %d of set %d invalid (%d)\n", total + i, set, k); ZOLTAN_FILE_close(finassign); DEBUG_TRACE_END(0, yo); return (1); } if ((int) assignment[k - 1] != -1) { printf("ERROR: In assignment file `%s'\n", inassignname); printf(" Vertex %d assigned to multiple sets\n", k); ZOLTAN_FILE_close(finassign); DEBUG_TRACE_END(0, yo); return (1); } assignment[k - 1] = (short) set; } total += size; j = ZOLTAN_FILE_scanf(finassign, "%d", &size); ++set; if (j != 1) { if (total != nvtxs) { printf("ERROR: Too few values in assignment file `%s'.\n", inassignname); ZOLTAN_FILE_close(finassign); DEBUG_TRACE_END(0, yo); return (1); } else { done = TRUE; size = 0; } } if (size < 0) { printf("ERROR: In assignment file `%s'\n", inassignname); printf(" Size of set %d less than zero (%d)\n", set, size); ZOLTAN_FILE_close(finassign); DEBUG_TRACE_END(0, yo); return (1); } if (total + size > nvtxs) { printf("ERROR: In assignment file `%s'\n", inassignname); printf(" Total set sizes greater than nvtxs (%d)\n", nvtxs); ZOLTAN_FILE_close(finassign); DEBUG_TRACE_END(0, yo); return (1); } } ZOLTAN_FILE_close(finassign); DEBUG_TRACE_END(0, yo); return (0); }
int chaco_input_geom( ZOLTAN_FILE *fingeom, /* geometry input file */ char *geomname, /* name of geometry file */ int nvtxs, /* number of coordinates to read */ int *igeom, /* dimensionality of geometry */ float **x, /* coordinates of vertices */ float **y, float **z ) { const char *yo = "chaco_input_geom"; float xc, yc, zc =0; /* first x, y, z coordinate */ int nread; /* number of lines of coordinates read */ int flag; /* any bad data at end of file? */ int line_num; /* counts input lines in file */ int end_flag; /* return conditional */ int ndims; /* number of values in an input line */ int i=0; /* loop counter */ DEBUG_TRACE_START(0, yo); *x = *y = *z = NULL; line_num = 0; end_flag = 1; while (end_flag == 1) { xc = read_val(fingeom, &end_flag); ++line_num; } if (end_flag == -1) { printf("No values found in geometry file `%s'\n", geomname); ZOLTAN_FILE_close(fingeom); return (1); } ndims = 1; yc = read_val(fingeom, &end_flag); if (end_flag == 0) { ndims = 2; zc = read_val(fingeom, &end_flag); if (end_flag == 0) { ndims = 3; read_val(fingeom, &end_flag); if (!end_flag) { printf("Too many values on input line of geometry file `%s'\n", geomname); printf(" Maximum dimensionality is 3\n"); ZOLTAN_FILE_close(fingeom); return (1); } } } *igeom = ndims; *x = (float *) malloc((unsigned) nvtxs * sizeof(float)); (*x)[0] = xc; if (ndims > 1) { *y = (float *) malloc((unsigned) nvtxs * sizeof(float)); (*y)[0] = yc; } if (ndims > 2) { *z = (float *) malloc((unsigned) nvtxs * sizeof(float)); (*z)[0] = zc; } for (nread = 1; nread < nvtxs; nread++) { ++line_num; if (ndims == 1) { i = ZOLTAN_FILE_scanf(fingeom, "%f", &((*x)[nread])); } else if (ndims == 2) { i = ZOLTAN_FILE_scanf(fingeom, "%f%f", &((*x)[nread]), &((*y)[nread])); } else if (ndims == 3) { i = ZOLTAN_FILE_scanf(fingeom, "%f%f%f", &((*x)[nread]), &((*y)[nread]), &((*z)[nread])); } if (i == EOF) { printf("Too few lines of values in geometry file; nvtxs=%d, but only %d read\n", nvtxs, nread); ZOLTAN_FILE_close(fingeom); return (1); } else if (i != ndims) { printf("Wrong number of values in line %d of geometry file `%s'\n", line_num, geomname); ZOLTAN_FILE_close(fingeom); return (1); } } /* Check for spurious extra stuff in file. */ flag = 0; end_flag = 0; while (!flag && end_flag != -1) { read_val(fingeom, &end_flag); if (!end_flag) flag = 1; } if (flag && Debug_Chaco_Input) { printf("Warning: possible error in geometry file `%s'\n", geomname); printf(" Numerical data found after expected end of file\n"); } ZOLTAN_FILE_close(fingeom); DEBUG_TRACE_END(0, yo); return (0); }
int mm_read_unsymmetric_sparse(const char *fname, int *M_, int *N_, int *nz_, double **val_, int **I_, int **J_) { ZOLTAN_FILE *f; MM_typecode matcode; int M, N, nz; int i; double *val; int *I, *J; f = ZOLTAN_FILE_open(fname, "r", STANDARD); if (f == NULL) return -1; if (mm_read_banner(f, &matcode) != 0) { printf("mm_read_unsymetric: Could not process Matrix Market banner "); printf(" in file [%s]\n", fname); return -1; } if ( !(mm_is_real(matcode) && mm_is_matrix(matcode) && mm_is_sparse(matcode))) { fprintf(stderr, "Sorry, this application does not support "); fprintf(stderr, "Market Market type: [%s]\n", mm_typecode_to_str(matcode)); return -1; } /* find out size of sparse matrix: M, N, nz .... */ if (mm_read_mtx_crd_size(f, &M, &N, &nz) !=0) { fprintf(stderr, "read_unsymmetric_sparse(): could not parse matrix size.\n"); return -1; } *M_ = M; *N_ = N; *nz_ = nz; /* reseve memory for matrices */ I = (int *) malloc(nz * sizeof(int)); J = (int *) malloc(nz * sizeof(int)); val = (double *) malloc(nz * sizeof(double)); *val_ = val; *I_ = I; *J_ = J; /* NOTE: when reading in doubles, ANSI C requires the use of the "l" */ /* specifier as in "%lg", "%lf", "%le", otherwise errors will occur */ /* (ANSI C X3.159-1989, Sec. 4.9.6.2, p. 136 lines 13-15) */ for (i=0; i<nz; i++) { ZOLTAN_FILE_scanf(f, "%d %d %lg\n", &I[i], &J[i], &val[i]); I[i]--; /* adjust from 1-based to 0-based */ J[i]--; } ZOLTAN_FILE_close(f); return 0; }
/* Read from file and set up hypergraph. */ int read_hypergraph_file( int Proc, int Num_Proc, PROB_INFO_PTR prob, PARIO_INFO_PTR pio_info, MESH_INFO_PTR mesh ) { /* Local declarations. */ const char *yo = "read_hypergraph_file"; char cmesg[256]; int i, gnvtxs, distributed_pins = 0, edge, vertex, nextEdge; int nvtxs = 0, gnhedges = 0, nhedges = 0, npins = 0; int vwgt_dim=0, hewgt_dim=0, vtx, edgeSize, global_npins; int *hindex = NULL, *hvertex = NULL, *hvertex_proc = NULL; int *hgid = NULL; float *hewgts = NULL, *vwgts = NULL; ZOLTAN_FILE* fp = NULL; int base = 0; /* Smallest vertex number; usually zero or one. */ char filename[256]; /* Variables that allow graph-based functions to be reused. */ /* If no chaco.graph or chaco.coords files exist, values are NULL or 0, * since graph is not being built. If chaco.graph and/or chaco.coords * exist, these arrays are filled and values stored in mesh. * Including these files allows for comparison of HG methods with other * methods, along with visualization of results and comparison of * LB_Eval results. */ int ch_nvtxs = 0; /* Temporary values for chaco_read_graph. */ #ifdef KDDKDD int ch_vwgt_dim = 0; /* Their values are ignored, as vertex */ #endif float *ch_vwgts = NULL; /* info is provided by hypergraph file. */ int *ch_start = NULL, *ch_adj = NULL, ch_ewgt_dim = 0; short *ch_assignments = NULL; float *ch_ewgts = NULL; int ch_ndim = 0; float *ch_x = NULL, *ch_y = NULL, *ch_z = NULL; int ch_no_geom = TRUE; /* Assume no geometry info is given; reset if it is provided. */ int file_error = 0; /***************************** BEGIN EXECUTION ******************************/ DEBUG_TRACE_START(Proc, yo); if (Proc == 0) { /* Open and read the hypergraph file. */ if (pio_info->file_type == HYPERGRAPH_FILE) sprintf(filename, "%s.hg", pio_info->pexo_fname); else if (pio_info->file_type == MATRIXMARKET_FILE) sprintf(filename, "%s.mtx", pio_info->pexo_fname); else { sprintf(cmesg, "fatal: invalid file type %d", pio_info->file_type); Gen_Error(0, cmesg); return 0; } fp = ZOLTAN_FILE_open(filename, "r", pio_info->file_comp); file_error = (fp == NULL); } MPI_Bcast(&file_error, 1, MPI_INT, 0, MPI_COMM_WORLD); if (file_error) { sprintf(cmesg, "fatal: Could not open hypergraph file %s",pio_info->pexo_fname); Gen_Error(0, cmesg); return 0; } if (pio_info->file_type == HYPERGRAPH_FILE) { /* read the array in on processor 0 */ if (Proc == 0) { if (HG_readfile(Proc, fp, &nvtxs, &nhedges, &npins, &hindex, &hvertex, &vwgt_dim, &vwgts, &hewgt_dim, &hewgts, &base) != 0){ Gen_Error(0, "fatal: Error returned from HG_readfile"); return 0; } } } else if (pio_info->file_type == MATRIXMARKET_FILE) { /* * pio_info->chunk_reader == 0 (the usual case) * process 0 will read entire file in MM_readfile, * and will distribute vertices in chaco_dist_graph and pins in * dist_hyperedges later. (distributed_pins==0) * * pio_info->chunk_reader == 1 ("initial read = chunks" in zdrive.inp) * process 0 will read the file in chunks, and will send vertices * and pins to other processes before reading the next chunk, all * in MM_readfile. (distributed_pins==1) */ if (MM_readfile(Proc, Num_Proc, fp, pio_info, &nvtxs, /* global number of vertices */ &nhedges, /* global number of hyperedges */ &npins, /* local number of pins */ &hindex, &hvertex, &vwgt_dim, &vwgts, &hewgt_dim, &hewgts, &ch_start, &ch_adj, &ch_ewgt_dim, &ch_ewgts, &base, &global_npins)) { Gen_Error(0, "fatal: Error returned from MM_readfile"); return 0; } if (Proc == 0) ZOLTAN_FILE_close(fp); if ((Num_Proc > 1) && pio_info->chunk_reader && (global_npins > Num_Proc)){ distributed_pins = 1; } else{ distributed_pins = 0; } } #ifdef KDDKDD { /* If CHACO graph file is available, read it. */ sprintf(filename, "%s.graph", pio_info->pexo_fname); fp = ZOLTAN_FILE_open(filename, "r", pio_info->file_comp); file_error = #ifndef ZOLTAN_COMPRESS (fp == NULL); #else fp.error; #endif if (!file_error) { /* CHACO graph file is available. */ /* Assuming hypergraph vertices are same as chaco vertices. */ /* Chaco vertices and their weights are ignored in rest of function. */ if (chaco_input_graph(fp, filename, &ch_start, &ch_adj, &ch_nvtxs, &ch_vwgt_dim, &ch_vwgts, &ch_ewgt_dim, &ch_ewgts) != 0) { Gen_Error(0, "fatal: Error returned from chaco_input_graph"); return 0; } } else ch_nvtxs = nvtxs; /* If coordinate file is available, read it. */ sprintf(filename, "%s.coords", pio_info->pexo_fname); fp = ZOLTAN_FILE_open(filename, "r", pio_info->file_comp); file_error = #ifndef ZOLTAN_COMPRESS (fp == NULL); #else fp.error; #endif if (!file_error) { /* CHACO coordinates file is available. */ ch_no_geom = FALSE; if (chaco_input_geom(fpkdd, filename, ch_nvtxs, &ch_ndim, &ch_x, &ch_y, &ch_z) != 0) { Gen_Error(0, "fatal: Error returned from chaco_input_geom"); return 0; } } } #else /* KDDKDD */ ch_nvtxs = nvtxs; #endif /* KDDKDD */ { /* Read Chaco assignment file, if requested */ if (pio_info->init_dist_type == INITIAL_FILE) { sprintf(filename, "%s.assign", pio_info->pexo_fname); fp = ZOLTAN_FILE_open(filename, "r", pio_info->file_comp); if (fp == NULL) { sprintf(cmesg, "Error: Could not open Chaco assignment file %s; " "initial distribution cannot be read", filename); Gen_Error(0, cmesg); return 0; } else { /* read the coordinates in on processor 0 */ ch_assignments = (short *) malloc(nvtxs * sizeof(short)); if (nvtxs && !ch_assignments) { Gen_Error(0, "fatal: memory error in read_hypergraph_file"); return 0; } /* closes fpassign when done */ if (chaco_input_assign(fp, filename, ch_nvtxs, ch_assignments) != 0){ Gen_Error(0, "fatal: Error returned from chaco_input_assign"); return 0; } } } } MPI_Bcast(&base, 1, MPI_INT, 0, MPI_COMM_WORLD); if (distributed_pins){ gnhedges = nhedges; nhedges = 0; hewgt_dim = 0; hewgts = NULL; for (edge=0; edge<gnhedges; edge++){ edgeSize = hindex[edge+1] - hindex[edge]; if (edgeSize > 0) nhedges++; } hgid = (int *)malloc(nhedges * sizeof(int)); hvertex_proc = (int *)malloc(npins * sizeof(int)); nextEdge=0; vtx=0; for (edge=0; edge<gnhedges; edge++){ edgeSize = hindex[edge+1] - hindex[edge]; if (edgeSize > 0){ hgid[nextEdge] = edge+1; if (nextEdge < edge){ hindex[nextEdge+1] = hindex[nextEdge] + edgeSize; } for (vertex=0; vertex<edgeSize; vertex++,vtx++){ hvertex_proc[vtx] = ch_dist_proc(hvertex[vtx], NULL, 1); } nextEdge++; } } gnvtxs = nvtxs; nvtxs = ch_dist_num_vtx(Proc, NULL); if (ch_start){ /* need to include only vertices this process owns */ for (i=0,vertex=0; i<gnvtxs; i++){ if ((ch_start[i+1] > ch_start[vertex]) || /* vtx has adjacencies so it's mine */ (ch_dist_proc(i, NULL, 0) == Proc)) /* my vtx with no adjacencies */ { if (i > vertex){ ch_start[vertex+1] = ch_start[i+1]; } vertex++; } } } #if 0 debug_lists(Proc, Num_Proc, nhedges, hindex, hvertex, hvertex_proc, hgid); #endif } else{ /* Distribute hypergraph graph */ /* Use hypergraph vertex information and chaco edge information. */ if (!chaco_dist_graph(MPI_COMM_WORLD, pio_info, 0, &gnvtxs, &nvtxs, &ch_start, &ch_adj, &vwgt_dim, &vwgts, &ch_ewgt_dim, &ch_ewgts, &ch_ndim, &ch_x, &ch_y, &ch_z, &ch_assignments) != 0) { Gen_Error(0, "fatal: Error returned from chaco_dist_graph"); return 0; } if (!dist_hyperedges(MPI_COMM_WORLD, pio_info, 0, base, gnvtxs, &gnhedges, &nhedges, &hgid, &hindex, &hvertex, &hvertex_proc, &hewgt_dim, &hewgts, ch_assignments)) { Gen_Error(0, "fatal: Error returned from dist_hyperedges"); return 0; } } /* Initialize mesh structure for Hypergraph. */ mesh->data_type = HYPERGRAPH; mesh->num_elems = nvtxs; mesh->vwgt_dim = vwgt_dim; mesh->ewgt_dim = ch_ewgt_dim; mesh->elem_array_len = mesh->num_elems + 5; mesh->num_dims = ch_ndim; mesh->num_el_blks = 1; mesh->gnhedges = gnhedges; mesh->nhedges = nhedges; mesh->hewgt_dim = hewgt_dim; mesh->hgid = hgid; mesh->hindex = hindex; mesh->hvertex = hvertex; mesh->hvertex_proc = hvertex_proc; mesh->heNumWgts = nhedges; mesh->heWgtId = NULL; mesh->hewgts = hewgts; mesh->eb_etypes = (int *) malloc (5 * mesh->num_el_blks * sizeof(int)); if (!mesh->eb_etypes) { Gen_Error(0, "fatal: insufficient memory"); return 0; } mesh->eb_ids = mesh->eb_etypes + mesh->num_el_blks; mesh->eb_cnts = mesh->eb_ids + mesh->num_el_blks; mesh->eb_nnodes = mesh->eb_cnts + mesh->num_el_blks; mesh->eb_nattrs = mesh->eb_nnodes + mesh->num_el_blks; mesh->eb_names = (char **) malloc (mesh->num_el_blks * sizeof(char *)); if (!mesh->eb_names) { Gen_Error(0, "fatal: insufficient memory"); return 0; } mesh->eb_etypes[0] = -1; mesh->eb_ids[0] = 1; mesh->eb_cnts[0] = nvtxs; mesh->eb_nattrs[0] = 0; /* * Each element has one set of coordinates (i.e., node) if a coords file * was provided; zero otherwise. */ MPI_Bcast( &ch_no_geom, 1, MPI_INT, 0, MPI_COMM_WORLD); if (ch_no_geom) mesh->eb_nnodes[0] = 0; else mesh->eb_nnodes[0] = 1; /* allocate space for name */ mesh->eb_names[0] = (char *) malloc((MAX_STR_LENGTH+1) * sizeof(char)); if (!mesh->eb_names[0]) { Gen_Error(0, "fatal: insufficient memory"); return 0; } strcpy(mesh->eb_names[0], "hypergraph"); /* allocate the element structure array */ mesh->elements = (ELEM_INFO_PTR) malloc (mesh->elem_array_len * sizeof(ELEM_INFO)); if (!(mesh->elements)) { Gen_Error(0, "fatal: insufficient memory"); return 0; } /* * initialize all of the element structs as unused by * setting the globalID to -1 */ for (i = 0; i < mesh->elem_array_len; i++) initialize_element(&(mesh->elements[i])); /* * now fill the element structure array with the * information from the Chaco file * Use hypergraph vertex information and chaco edge information. */ if (!chaco_fill_elements(Proc, Num_Proc, prob, mesh, gnvtxs, nvtxs, ch_start, ch_adj, vwgt_dim, vwgts, ch_ewgt_dim, ch_ewgts, ch_ndim, ch_x, ch_y, ch_z, ch_assignments, base)) { Gen_Error(0, "fatal: Error returned from chaco_fill_elements"); return 0; } #if 0 debug_elements(Proc, Num_Proc, mesh->num_elems,mesh->elements); #endif safe_free((void **)(void *) &vwgts); safe_free((void **)(void *) &ch_ewgts); safe_free((void **)(void *) &ch_vwgts); safe_free((void **)(void *) &ch_x); safe_free((void **)(void *) &ch_y); safe_free((void **)(void *) &ch_z); safe_free((void **)(void *) &ch_start); safe_free((void **)(void *) &ch_adj); safe_free((void **)(void *) &ch_assignments); if (Debug_Driver > 3) print_distributed_mesh(Proc, Num_Proc, mesh); DEBUG_TRACE_END(Proc, yo); return 1; }