void EuclidGetDimensions(void *Ain, HYPRE_Int *beg_row, HYPRE_Int *rowsLocal, HYPRE_Int *rowsGlobal) { START_FUNC_DH Mat A = (Mat)Ain; HYPRE_Int first, ierr, last; HYPRE_Int rows, cols; ierr = MatGetOwnershipRange(A, &first, &last); if (ierr) { hypre_sprintf(msgBuf_dh, "PETSc's MatGetOwnershipRange failed"); SET_V_ERROR(msgBuf_dh); } ierr = MatGetSize(A, &rows, &cols); if (ierr) { hypre_sprintf(msgBuf_dh, "PETSc'MatGetSize failed"); SET_V_ERROR(msgBuf_dh); } if (rows != cols) { hypre_sprintf(msgBuf_dh, "matrix is not square; global dimensions: rows = %i, cols = %i", rows, cols); SET_V_ERROR(msgBuf_dh); } *beg_row = first; *rowsLocal = last - first; *rowsGlobal = rows; END_FUNC_DH }
void EuclidGetDimensions(void *A, HYPRE_Int *beg_row, HYPRE_Int *rowsLocal, HYPRE_Int *rowsGlobal) { START_FUNC_DH HYPRE_Int ierr, m, n; HYPRE_Int row_start, row_end, col_start, col_end; HYPRE_ParCSRMatrix mat = (HYPRE_ParCSRMatrix) A; ierr = HYPRE_ParCSRMatrixGetDims(mat, &m, &n); if (ierr) { hypre_sprintf(msgBuf_dh, "HYPRE_ParCSRMatrixGetDims() returned %i", ierr); SET_V_ERROR(msgBuf_dh); } ierr = HYPRE_ParCSRMatrixGetLocalRange(mat, &row_start, &row_end, &col_start, &col_end); if (ierr) { hypre_sprintf(msgBuf_dh, "HYPRE_ParCSRMatrixGetLocalRange() returned %i", ierr); SET_V_ERROR(msgBuf_dh); } /* hypre_fprintf(stderr, "\n##### [%i] EuclidGetDimensions: m= %i n= %i beg_row= %i row_end= %i col_start= %i col_end= %i\n", myid_dh, m,n,row_start,row_end,col_start,col_end); */ *beg_row = row_start; *rowsLocal = (row_end - row_start + 1); *rowsGlobal = n; END_FUNC_DH }
hypre_ParVector *hypre_ParVectorRead( MPI_Comm comm, const char *file_name ) { char new_file_name[80]; hypre_ParVector *par_vector; HYPRE_Int my_id, num_procs; HYPRE_Int *partitioning; HYPRE_Int global_size, i; FILE *fp; hypre_MPI_Comm_rank(comm,&my_id); hypre_MPI_Comm_size(comm,&num_procs); partitioning = hypre_CTAlloc(HYPRE_Int,num_procs+1); hypre_sprintf(new_file_name,"%s.INFO.%d",file_name,my_id); fp = fopen(new_file_name, "r"); hypre_fscanf(fp, "%d\n", &global_size); #ifdef HYPRE_NO_GLOBAL_PARTITION for (i=0; i < 2; i++) hypre_fscanf(fp, "%d\n", &partitioning[i]); fclose (fp); #else for (i=0; i < num_procs; i++) hypre_fscanf(fp, "%d\n", &partitioning[i]); fclose (fp); partitioning[num_procs] = global_size; #endif par_vector = hypre_CTAlloc(hypre_ParVector, 1); hypre_ParVectorComm(par_vector) = comm; hypre_ParVectorGlobalSize(par_vector) = global_size; #ifdef HYPRE_NO_GLOBAL_PARTITION hypre_ParVectorFirstIndex(par_vector) = partitioning[0]; hypre_ParVectorLastIndex(par_vector) = partitioning[1]-1; #else hypre_ParVectorFirstIndex(par_vector) = partitioning[my_id]; hypre_ParVectorLastIndex(par_vector) = partitioning[my_id+1]-1; #endif hypre_ParVectorPartitioning(par_vector) = partitioning; hypre_ParVectorOwnsData(par_vector) = 1; hypre_ParVectorOwnsPartitioning(par_vector) = 1; hypre_sprintf(new_file_name,"%s.%d",file_name,my_id); hypre_ParVectorLocalVector(par_vector) = hypre_SeqVectorRead(new_file_name); /* multivector code not written yet >>> */ hypre_assert( hypre_ParVectorNumVectors(par_vector) == 1 ); return par_vector; }
void readVec(Vec_dh *bout, char *ft, char *fn, HYPRE_Int ignore) { START_FUNC_DH *bout = NULL; if (fn == NULL) { SET_V_ERROR("passed NULL filename; can't open for reading!"); } if (!strcmp(ft, "csr") || !strcmp(ft, "trip")) { Vec_dhRead(bout, ignore, fn); CHECK_V_ERROR; } else if (!strcmp(ft, "ebin")) { Vec_dhReadBIN(bout, fn); CHECK_V_ERROR; } #ifdef PETSC_MODE else if (!strcmp(ft, "petsc")) { Viewer_DH viewer; HYPRE_Int ierr; Vec bb; ierr = ViewerBinaryOpen_DH(comm_dh, fn, BINARY_WRONLY_DH, &viewer); if (ierr) { SET_V_ERROR("ViewerBinaryOpen failed! [PETSc lib]"); } ierr = VecLoad(viewer, &bb); if (ierr) { SET_V_ERROR("VecLoad failed! [PETSc lib]"); } ierr = ViewerDestroy_DH(viewer); if (ierr) { SET_V_ERROR("ViewerDestroy failed! [PETSc lib]"); } ierr = convertPetscToEuclidVec(bb, bout); if (ierr) { SET_V_ERROR("convertPetscToEuclidVec failed!"); } ierr = VecDestroy(bb); if (ierr) { SET_V_ERROR("VecDestroy failed! [PETSc lib]"); } } #else else if (!strcmp(ft, "petsc")) { hypre_sprintf(msgBuf_dh, "must recompile Euclid using petsc mode!"); SET_V_ERROR(msgBuf_dh); } #endif else { hypre_sprintf(msgBuf_dh, "unknown filetype: -ftin %s", ft); SET_V_ERROR(msgBuf_dh); } END_FUNC_DH }
void mat_dh_read_csr_private(HYPRE_Int *mOUT, HYPRE_Int **rpOUT, HYPRE_Int **cvalOUT, double **avalOUT, FILE* fp) { START_FUNC_DH HYPRE_Int i, m, nz, items; HYPRE_Int *rp, *cval; double *aval; /* read header line */ items = hypre_fscanf(fp,"%d %d",&m, &nz); if (items != 2) { SET_V_ERROR("failed to read header"); } else { hypre_printf("mat_dh_read_csr_private:: m= %i nz= %i\n", m, nz); } *mOUT = m; rp = *rpOUT = (HYPRE_Int*)MALLOC_DH((m+1)*sizeof(HYPRE_Int)); CHECK_V_ERROR; cval = *cvalOUT = (HYPRE_Int*)MALLOC_DH(nz*sizeof(HYPRE_Int)); CHECK_V_ERROR; aval = *avalOUT = (double*)MALLOC_DH(nz*sizeof(double)); CHECK_V_ERROR; /* read rp[] block */ for (i=0; i<=m; ++i) { items = hypre_fscanf(fp,"%d", &(rp[i])); if (items != 1) { hypre_sprintf(msgBuf_dh, "failed item %i of %i in rp block", i, m+1); SET_V_ERROR(msgBuf_dh); } } /* read cval[] block */ for (i=0; i<nz; ++i) { items = hypre_fscanf(fp,"%d", &(cval[i])); if (items != 1) { hypre_sprintf(msgBuf_dh, "failed item %i of %i in cval block", i, m+1); SET_V_ERROR(msgBuf_dh); } } /* read aval[] block */ for (i=0; i<nz; ++i) { items = hypre_fscanf(fp,"%lg", &(aval[i])); if (items != 1) { hypre_sprintf(msgBuf_dh, "failed item %i of %i in aval block", i, m+1); SET_V_ERROR(msgBuf_dh); } } END_FUNC_DH }
HYPRE_Int hypre_ParMultiVectorTempPrint(hypre_ParMultiVector *vector, const char *fileName) { HYPRE_Int i, ierr; char fullName[128]; hypre_ParVector * temp_vec; hypre_assert( vector != NULL ); temp_vec=hypre_ParVectorCreate(vector->comm,vector->global_size, vector->partitioning); hypre_assert(temp_vec!=NULL); temp_vec->owns_partitioning=0; temp_vec->local_vector->owns_data=0; /* no initialization for temp_vec needed! */ ierr = 0; for ( i = 0; i < vector->local_vector->num_vectors; i++ ) { hypre_sprintf( fullName, "%s.%d", fileName, i ); temp_vec->local_vector->data=vector->local_vector->data + i * vector->local_vector->size; ierr = ierr || hypre_ParVectorPrint(temp_vec, fullName); } ierr = ierr || hypre_ParVectorDestroy(temp_vec); /* line above won't free data or partitioning */ return ierr; }
void mat_dh_print_graph_private(HYPRE_Int m, HYPRE_Int beg_row, HYPRE_Int *rp, HYPRE_Int *cval, double *aval, HYPRE_Int *n2o, HYPRE_Int *o2n, Hash_i_dh hash, FILE* fp) { START_FUNC_DH HYPRE_Int i, j, row, col; double val; bool private_n2o = false; bool private_hash = false; if (n2o == NULL) { private_n2o = true; create_nat_ordering_private(m, &n2o); CHECK_V_ERROR; create_nat_ordering_private(m, &o2n); CHECK_V_ERROR; } if (hash == NULL) { private_hash = true; Hash_i_dhCreate(&hash, -1); CHECK_V_ERROR; } for (i=0; i<m; ++i) { row = n2o[i]; for (j=rp[row]; j<rp[row+1]; ++j) { col = cval[j]; if (col < beg_row || col >= beg_row+m) { HYPRE_Int tmp = col; /* nonlocal column: get permutation from hash table */ tmp = Hash_i_dhLookup(hash, col); CHECK_V_ERROR; if (tmp == -1) { hypre_sprintf(msgBuf_dh, "beg_row= %i m= %i; nonlocal column= %i not in hash table", beg_row, m, col); SET_V_ERROR(msgBuf_dh); } else { col = tmp; } } else { col = o2n[col]; } if (aval == NULL) { val = _MATLAB_ZERO_; } else { val = aval[j]; } hypre_fprintf(fp, "%i %i %g\n", 1+row+beg_row, 1+col, val); } } if (private_n2o) { destroy_nat_ordering_private(n2o); CHECK_V_ERROR; destroy_nat_ordering_private(o2n); CHECK_V_ERROR; } if (private_hash) { Hash_i_dhDestroy(hash); CHECK_V_ERROR; } END_FUNC_DH }
void HYPRE_DescribeError(HYPRE_Int ierr, char *msg) { if (ierr == 0) hypre_sprintf(msg,"[No error] "); if (ierr & HYPRE_ERROR_GENERIC) hypre_sprintf(msg,"[Generic error] "); if (ierr & HYPRE_ERROR_MEMORY) hypre_sprintf(msg,"[Memory error] "); if (ierr & HYPRE_ERROR_ARG) hypre_sprintf(msg,"[Error in argument %d] ", HYPRE_GetErrorArg()); if (ierr & HYPRE_ERROR_CONV) hypre_sprintf(msg,"[Method did not converge] "); }
void* hypre_ParCSRMultiVectorRead( MPI_Comm comm, void* ii_, const char* fileName ) { HYPRE_Int i, n, id; FILE* fp; char fullName[128]; mv_TempMultiVector* x; mv_InterfaceInterpreter* ii = (mv_InterfaceInterpreter*)ii_; hypre_MPI_Comm_rank( comm, &id ); n = 0; do { hypre_sprintf( fullName, "%s.%d.%d", fileName, n, id ); if ( (fp = fopen(fullName, "r")) ) { n++; fclose( fp ); } } while ( fp ); if ( n == 0 ) return NULL; x = (mv_TempMultiVector*) malloc(sizeof(mv_TempMultiVector)); hypre_assert( x != NULL ); x->interpreter = ii; x->numVectors = n; x->vector = (void**) calloc( n, sizeof(void*) ); hypre_assert( x->vector != NULL ); x->ownsVectors = 1; for ( i = 0; i < n; i++ ) { hypre_sprintf( fullName, "%s.%d", fileName, i ); x->vector[i] = hypre_ParReadVector( comm, fullName ); } x->mask = NULL; x->ownsMask = 0; return x; }
void PrintMatUsingGetRow(void* A, HYPRE_Int beg_row, HYPRE_Int m, HYPRE_Int *n2o_row, HYPRE_Int *n2o_col, char *filename) { START_FUNC_DH FILE *fp; HYPRE_Int *o2n_col = NULL, pe, i, j, *cval, len; HYPRE_Int newCol, newRow; double *aval; /* form inverse column permutation */ if (n2o_col != NULL) { o2n_col = (HYPRE_Int*)MALLOC_DH(m*sizeof(HYPRE_Int)); CHECK_V_ERROR; for (i=0; i<m; ++i) o2n_col[n2o_col[i]] = i; } for (pe=0; pe<np_dh; ++pe) { hypre_MPI_Barrier(comm_dh); if (myid_dh == pe) { if (pe == 0) { fp=fopen(filename, "w"); } else { fp=fopen(filename, "a"); } if (fp == NULL) { hypre_sprintf(msgBuf_dh, "can't open %s for writing\n", filename); SET_V_ERROR(msgBuf_dh); } for (i=0; i<m; ++i) { if (n2o_row == NULL) { EuclidGetRow(A, i+beg_row, &len, &cval, &aval); CHECK_V_ERROR; for (j=0; j<len; ++j) { hypre_fprintf(fp, "%i %i %g\n", i+1, cval[j], aval[j]); } EuclidRestoreRow(A, i, &len, &cval, &aval); CHECK_V_ERROR; } else { newRow = n2o_row[i] + beg_row; EuclidGetRow(A, newRow, &len, &cval, &aval); CHECK_V_ERROR; for (j=0; j<len; ++j) { newCol = o2n_col[cval[j]-beg_row] + beg_row; hypre_fprintf(fp, "%i %i %g\n", i+1, newCol, aval[j]); } EuclidRestoreRow(A, i, &len, &cval, &aval); CHECK_V_ERROR; } } fclose(fp); } } if (n2o_col != NULL) { FREE_DH(o2n_col); CHECK_V_ERROR; } END_FUNC_DH }
HYPRE_Int HYPRE_IJMatrixRead( const char *filename, MPI_Comm comm, HYPRE_Int type, HYPRE_IJMatrix *matrix_ptr ) { HYPRE_IJMatrix matrix; HYPRE_Int ilower, iupper, jlower, jupper; HYPRE_Int ncols, I, J; HYPRE_Complex value; HYPRE_Int myid, ret; char new_filename[255]; FILE *file; hypre_MPI_Comm_rank(comm, &myid); hypre_sprintf(new_filename,"%s.%05d", filename, myid); if ((file = fopen(new_filename, "r")) == NULL) { hypre_error_in_arg(1); return hypre_error_flag; } hypre_fscanf(file, "%d %d %d %d", &ilower, &iupper, &jlower, &jupper); HYPRE_IJMatrixCreate(comm, ilower, iupper, jlower, jupper, &matrix); HYPRE_IJMatrixSetObjectType(matrix, type); HYPRE_IJMatrixInitialize(matrix); /* It is important to ensure that whitespace follows the index value to help * catch mistakes in the input file. See comments in IJVectorRead(). */ ncols = 1; while ( (ret = hypre_fscanf(file, "%d %d%*[ \t]%le", &I, &J, &value)) != EOF ) { if (ret != 3) { hypre_error_w_msg(HYPRE_ERROR_GENERIC, "Error in IJ matrix input file."); return hypre_error_flag; } if (I < ilower || I > iupper) HYPRE_IJMatrixAddToValues(matrix, 1, &ncols, &I, &J, &value); else HYPRE_IJMatrixSetValues(matrix, 1, &ncols, &I, &J, &value); } HYPRE_IJMatrixAssemble(matrix); fclose(file); *matrix_ptr = matrix; return hypre_error_flag; }
HYPRE_Int hypre_ParCSRBooleanMatrixPrint( hypre_ParCSRBooleanMatrix *matrix, const char *file_name ) { MPI_Comm comm = hypre_ParCSRBooleanMatrix_Get_Comm(matrix); HYPRE_Int global_num_rows = hypre_ParCSRBooleanMatrix_Get_GlobalNRows(matrix); HYPRE_Int global_num_cols = hypre_ParCSRBooleanMatrix_Get_GlobalNCols(matrix); HYPRE_Int *col_map_offd = hypre_ParCSRBooleanMatrix_Get_ColMapOffd(matrix); HYPRE_Int *row_starts = hypre_ParCSRBooleanMatrix_Get_RowStarts(matrix); HYPRE_Int *col_starts = hypre_ParCSRBooleanMatrix_Get_ColStarts(matrix); HYPRE_Int my_id, i, num_procs; char new_file_d[80], new_file_o[80], new_file_info[80]; HYPRE_Int ierr = 0; FILE *fp; HYPRE_Int num_cols_offd = 0; if (hypre_ParCSRBooleanMatrix_Get_Offd(matrix)) num_cols_offd = hypre_CSRBooleanMatrix_Get_NCols(hypre_ParCSRBooleanMatrix_Get_Offd(matrix)); hypre_MPI_Comm_rank(comm, &my_id); hypre_MPI_Comm_size(comm, &num_procs); hypre_sprintf(new_file_d,"%s.D.%d",file_name,my_id); hypre_sprintf(new_file_o,"%s.O.%d",file_name,my_id); hypre_sprintf(new_file_info,"%s.INFO.%d",file_name,my_id); hypre_CSRBooleanMatrixPrint(hypre_ParCSRBooleanMatrix_Get_Diag(matrix),new_file_d); if (num_cols_offd != 0) hypre_CSRBooleanMatrixPrint(hypre_ParCSRBooleanMatrix_Get_Offd(matrix), new_file_o); fp = fopen(new_file_info, "w"); hypre_fprintf(fp, "%d\n", global_num_rows); hypre_fprintf(fp, "%d\n", global_num_cols); hypre_fprintf(fp, "%d\n", num_cols_offd); for (i=0; i < num_procs; i++) hypre_fprintf(fp, "%d %d\n", row_starts[i], col_starts[i]); for (i=0; i < num_cols_offd; i++) hypre_fprintf(fp, "%d\n", col_map_offd[i]); fclose(fp); return ierr; }
void EuclidRestoreRow(void *A, HYPRE_Int row, HYPRE_Int *len, HYPRE_Int **ind, double **val) { START_FUNC_DH HYPRE_Int ierr; HYPRE_ParCSRMatrix mat = (HYPRE_ParCSRMatrix) A; ierr = HYPRE_ParCSRMatrixRestoreRow(mat, row, len, ind, val); if (ierr) { hypre_sprintf(msgBuf_dh, "HYPRE_ParCSRMatrixRestoreRow(row= %i) returned %i", row+1, ierr); SET_V_ERROR(msgBuf_dh); } END_FUNC_DH }
void EuclidRestoreRow(void *Ain, HYPRE_Int row, HYPRE_Int *len, HYPRE_Int **ind, double **val) { START_FUNC_DH Mat A = (Mat)Ain; HYPRE_Int ierr; ierr = MatRestoreRow(A, row, len, ind, val); if (ierr) { hypre_sprintf(msgBuf_dh, "PETSc's MatRestoreRow bombed for row= %i", row); SET_V_ERROR(msgBuf_dh); } END_FUNC_DH }
HYPRE_Int hypre_ParVectorPrint( hypre_ParVector *vector, const char *file_name ) { char new_file_name[80]; hypre_Vector *local_vector; MPI_Comm comm; HYPRE_Int my_id, num_procs, i; HYPRE_Int *partitioning; HYPRE_Int global_size; FILE *fp; if (!vector) { hypre_error_in_arg(1); return hypre_error_flag; } local_vector = hypre_ParVectorLocalVector(vector); comm = hypre_ParVectorComm(vector); partitioning = hypre_ParVectorPartitioning(vector); global_size = hypre_ParVectorGlobalSize(vector); hypre_MPI_Comm_rank(comm,&my_id); hypre_MPI_Comm_size(comm,&num_procs); hypre_sprintf(new_file_name,"%s.%d",file_name,my_id); hypre_SeqVectorPrint(local_vector,new_file_name); hypre_sprintf(new_file_name,"%s.INFO.%d",file_name,my_id); fp = fopen(new_file_name, "w"); hypre_fprintf(fp, "%d\n", global_size); #ifdef HYPRE_NO_GLOBAL_PARTITION for (i=0; i < 2; i++) hypre_fprintf(fp, "%d\n", partitioning[i]); #else for (i=0; i < num_procs; i++) hypre_fprintf(fp, "%d\n", partitioning[i]); #endif fclose (fp); return hypre_error_flag; }
HYPRE_Int hypre_InitMemoryDebugDML( HYPRE_Int id ) { HYPRE_Int *iptr; /* do this to get the Debug Malloc Library started/initialized */ iptr = hypre_TAlloc(HYPRE_Int, 1); hypre_TFree(iptr); dmalloc_logpath = dmalloc_logpath_memory; hypre_sprintf(dmalloc_logpath, "dmalloc.log.%04d", id); return 0; }
void EuclidGetRow(void *A, HYPRE_Int globalRow, HYPRE_Int *len, HYPRE_Int **ind, double **val) { START_FUNC_DH Mat_dh B = (Mat_dh)A; HYPRE_Int row = globalRow - B->beg_row; if (row > B->m) { hypre_sprintf(msgBuf_dh, "requested globalRow= %i, which is local row= %i, but only have %i rows!", globalRow, row, B->m); SET_V_ERROR(msgBuf_dh); } *len = B->rp[row+1] - B->rp[row]; if (ind != NULL) *ind = B->cval + B->rp[row]; if (val != NULL) *val = B->aval + B->rp[row]; END_FUNC_DH }
HYPRE_Int hypre_ParCSRMultiVectorPrint( void* x_, const char* fileName ) { HYPRE_Int i, ierr; mv_TempMultiVector* x; char fullName[128]; x = (mv_TempMultiVector*)x_; hypre_assert( x != NULL ); ierr = 0; for ( i = 0; i < x->numVectors; i++ ) { hypre_sprintf( fullName, "%s.%d", fileName, i ); ierr = ierr || hypre_ParPrintVector( x->vector[i], fullName ); } return ierr; }
void Euclid_dhInputHypreMat(Euclid_dh ctx, HYPRE_ParCSRMatrix A) { START_FUNC_DH HYPRE_Int M, N; HYPRE_Int beg_row, end_row, junk; /* get dimension and ownership information */ HYPRE_ParCSRMatrixGetDims(A, &M , &N); if (M != N) { hypre_sprintf(msgBuf_dh, "Global matrix is not square: M= %i, N= %i", M, N); SET_V_ERROR(msgBuf_dh); } HYPRE_ParCSRMatrixGetLocalRange(A, &beg_row, &end_row, &junk, &junk); ctx->m = end_row - beg_row + 1; ctx->n = M; ctx->A = (void*)A; END_FUNC_DH }
HYPRE_Int hypre_ParCSRBooleanMatrixPrintIJ( hypre_ParCSRBooleanMatrix *matrix, const char *filename ) { MPI_Comm comm = hypre_ParCSRBooleanMatrix_Get_Comm(matrix); HYPRE_Int global_num_rows = hypre_ParCSRBooleanMatrix_Get_GlobalNRows(matrix); HYPRE_Int global_num_cols = hypre_ParCSRBooleanMatrix_Get_GlobalNCols(matrix); HYPRE_Int first_row_index = hypre_ParCSRBooleanMatrix_Get_StartRow(matrix); HYPRE_Int first_col_diag = hypre_ParCSRBooleanMatrix_Get_FirstColDiag(matrix); HYPRE_Int *col_map_offd = hypre_ParCSRBooleanMatrix_Get_ColMapOffd(matrix); HYPRE_Int num_rows = hypre_ParCSRBooleanMatrix_Get_NRows(matrix); HYPRE_Int *diag_i; HYPRE_Int *diag_j; HYPRE_Int *offd_i; HYPRE_Int *offd_j; HYPRE_Int myid, i, j, I, J; HYPRE_Int ierr = 0; char new_filename[255]; FILE *file; hypre_CSRBooleanMatrix *diag = hypre_ParCSRBooleanMatrix_Get_Diag(matrix); hypre_CSRBooleanMatrix *offd = hypre_ParCSRBooleanMatrix_Get_Offd(matrix); HYPRE_Int num_cols_offd = 0; if (offd) num_cols_offd = hypre_CSRBooleanMatrix_Get_NCols(hypre_ParCSRBooleanMatrix_Get_Offd(matrix)); hypre_MPI_Comm_rank(comm, &myid); hypre_sprintf(new_filename,"%s.%05d", filename, myid); if ((file = fopen(new_filename, "w")) == NULL) { hypre_printf("Error: can't open output file %s\n", new_filename); exit(1); } hypre_fprintf(file, "%d, %d\n", global_num_rows, global_num_cols); hypre_fprintf(file, "%d\n", num_rows); diag_i = hypre_CSRBooleanMatrix_Get_I(diag); diag_j = hypre_CSRBooleanMatrix_Get_J(diag); if (num_cols_offd) { offd_i = hypre_CSRBooleanMatrix_Get_I(offd); offd_j = hypre_CSRBooleanMatrix_Get_J(offd); } for (i = 0; i < num_rows; i++) { I = first_row_index + i; /* print diag columns */ for (j = diag_i[i]; j < diag_i[i+1]; j++) { J = first_col_diag + diag_j[j]; hypre_fprintf(file, "%d, %d\n", I, J ); } /* print offd columns */ if (num_cols_offd) { for (j = offd_i[i]; j < offd_i[i+1]; j++) { J = col_map_offd[offd_j[j]]; hypre_fprintf(file, "%d, %d \n", I, J); } } } fclose(file); return ierr; }
hypre_ParCSRBooleanMatrix * hypre_ParCSRBooleanMatrixRead( MPI_Comm comm, const char *file_name ) { hypre_ParCSRBooleanMatrix *matrix; hypre_CSRBooleanMatrix *diag; hypre_CSRBooleanMatrix *offd; HYPRE_Int my_id, i, num_procs; char new_file_d[80], new_file_o[80], new_file_info[80]; HYPRE_Int global_num_rows, global_num_cols, num_cols_offd; HYPRE_Int local_num_rows; HYPRE_Int *row_starts; HYPRE_Int *col_starts; HYPRE_Int *col_map_offd; FILE *fp; HYPRE_Int equal = 1; hypre_MPI_Comm_rank(comm,&my_id); hypre_MPI_Comm_size(comm,&num_procs); row_starts = hypre_CTAlloc(HYPRE_Int, num_procs+1); col_starts = hypre_CTAlloc(HYPRE_Int, num_procs+1); hypre_sprintf(new_file_d,"%s.D.%d",file_name,my_id); hypre_sprintf(new_file_o,"%s.O.%d",file_name,my_id); hypre_sprintf(new_file_info,"%s.INFO.%d",file_name,my_id); fp = fopen(new_file_info, "r"); hypre_fscanf(fp, "%d", &global_num_rows); hypre_fscanf(fp, "%d", &global_num_cols); hypre_fscanf(fp, "%d", &num_cols_offd); for (i=0; i < num_procs; i++) hypre_fscanf(fp, "%d %d", &row_starts[i], &col_starts[i]); row_starts[num_procs] = global_num_rows; col_starts[num_procs] = global_num_cols; col_map_offd = hypre_CTAlloc(HYPRE_Int, num_cols_offd); for (i=0; i < num_cols_offd; i++) hypre_fscanf(fp, "%d", &col_map_offd[i]); fclose(fp); for (i=num_procs; i >= 0; i--) if (row_starts[i] != col_starts[i]) { equal = 0; break; } if (equal) { hypre_TFree(col_starts); col_starts = row_starts; } diag = hypre_CSRBooleanMatrixRead(new_file_d); local_num_rows = hypre_CSRBooleanMatrix_Get_NRows(diag); if (num_cols_offd) { offd = hypre_CSRBooleanMatrixRead(new_file_o); } else offd = hypre_CSRBooleanMatrixCreate(local_num_rows,0,0); matrix = hypre_CTAlloc(hypre_ParCSRBooleanMatrix, 1); hypre_ParCSRBooleanMatrix_Get_Comm(matrix) = comm; hypre_ParCSRBooleanMatrix_Get_GlobalNRows(matrix) = global_num_rows; hypre_ParCSRBooleanMatrix_Get_GlobalNCols(matrix) = global_num_cols; hypre_ParCSRBooleanMatrix_Get_StartRow(matrix) = row_starts[my_id]; hypre_ParCSRBooleanMatrix_Get_FirstColDiag(matrix) = col_starts[my_id]; hypre_ParCSRBooleanMatrix_Get_RowStarts(matrix) = row_starts; hypre_ParCSRBooleanMatrix_Get_ColStarts(matrix) = col_starts; hypre_ParCSRBooleanMatrix_Get_CommPkg(matrix) = NULL; /* set defaults */ hypre_ParCSRBooleanMatrix_Get_OwnsData(matrix) = 1; hypre_ParCSRBooleanMatrix_Get_OwnsRowStarts(matrix) = 1; hypre_ParCSRBooleanMatrix_Get_OwnsColStarts(matrix) = 1; if (row_starts == col_starts) hypre_ParCSRBooleanMatrix_Get_OwnsColStarts(matrix) = 0; hypre_ParCSRBooleanMatrix_Get_Diag(matrix) = diag; hypre_ParCSRBooleanMatrix_Get_Offd(matrix) = offd; if (num_cols_offd) hypre_ParCSRBooleanMatrix_Get_ColMapOffd(matrix) = col_map_offd; else hypre_ParCSRBooleanMatrix_Get_ColMapOffd(matrix) = NULL; return matrix; }
HYPRE_Int hypre_StructCoarsen( hypre_StructGrid *fgrid, hypre_Index index, hypre_Index stride, HYPRE_Int prune, hypre_StructGrid **cgrid_ptr ) { hypre_StructGrid *cgrid; MPI_Comm comm; HYPRE_Int ndim; hypre_BoxArray *my_boxes; hypre_Index periodic; hypre_Index ilower, iupper; hypre_Box *box; hypre_Box *new_box; hypre_Box *bounding_box; HYPRE_Int i, j, myid, count; HYPRE_Int info_size, max_nentries; HYPRE_Int num_entries; HYPRE_Int *fids, *cids; hypre_Index new_dist; hypre_IndexRef max_distance; HYPRE_Int proc, id; HYPRE_Int coarsen_factor, known; HYPRE_Int num, last_proc; #if 0 hypre_StructAssumedPart *fap = NULL, *cap = NULL; #endif hypre_BoxManager *fboxman, *cboxman; hypre_BoxManEntry *entries; hypre_BoxManEntry *entry; void *entry_info = NULL; #if TIME_DEBUG HYPRE_Int tindex; char new_title[80]; hypre_sprintf(new_title,"Coarsen.%d",s_coarsen_num); tindex = hypre_InitializeTiming(new_title); s_coarsen_num++; hypre_BeginTiming(tindex); #endif hypre_SetIndex(ilower, 0); hypre_SetIndex(iupper, 0); /* get relevant information from the fine grid */ fids = hypre_StructGridIDs(fgrid); fboxman = hypre_StructGridBoxMan(fgrid); comm = hypre_StructGridComm(fgrid); ndim = hypre_StructGridNDim(fgrid); max_distance = hypre_StructGridMaxDistance(fgrid); /* initial */ hypre_MPI_Comm_rank(comm, &myid ); /* create new coarse grid */ hypre_StructGridCreate(comm, ndim, &cgrid); /* coarsen my boxes and create the coarse grid ids (same as fgrid) */ my_boxes = hypre_BoxArrayDuplicate(hypre_StructGridBoxes(fgrid)); cids = hypre_TAlloc(HYPRE_Int, hypre_BoxArraySize(my_boxes)); for (i = 0; i < hypre_BoxArraySize(my_boxes); i++) { box = hypre_BoxArrayBox(my_boxes, i); hypre_StructCoarsenBox(box, index, stride); cids[i] = fids[i]; } /* prune? */ /* zero volume boxes are needed when forming P and P^T */ if (prune) { count = 0; hypre_ForBoxI(i, my_boxes) { box = hypre_BoxArrayBox(my_boxes, i); if (hypre_BoxVolume(box)) { hypre_CopyBox(box, hypre_BoxArrayBox(my_boxes, count)); cids[count] = cids[i]; count++; } } hypre_BoxArraySetSize(my_boxes, count); }
void iluk_seq(Euclid_dh ctx) { START_FUNC_DH HYPRE_Int *rp, *cval, *diag; HYPRE_Int *CVAL; HYPRE_Int i, j, len, count, col, idx = 0; HYPRE_Int *list, *marker, *fill, *tmpFill; HYPRE_Int temp, m, from = ctx->from, to = ctx->to; HYPRE_Int *n2o_row, *o2n_col, beg_row, beg_rowP; double *AVAL; REAL_DH *work, *aval; Factor_dh F = ctx->F; SubdomainGraph_dh sg = ctx->sg; bool debug = false; if (logFile != NULL && Parser_dhHasSwitch(parser_dh, "-debug_ilu")) debug = true; m = F->m; rp = F->rp; cval = F->cval; fill = F->fill; diag = F->diag; aval = F->aval; work = ctx->work; count = rp[from]; if (sg == NULL) { SET_V_ERROR("subdomain graph is NULL"); } n2o_row = ctx->sg->n2o_row; o2n_col = ctx->sg->o2n_col; beg_row = ctx->sg->beg_row[myid_dh]; beg_rowP = ctx->sg->beg_rowP[myid_dh]; /* allocate and initialize working space */ list = (HYPRE_Int*)MALLOC_DH((m+1)*sizeof(HYPRE_Int)); CHECK_V_ERROR; marker = (HYPRE_Int*)MALLOC_DH(m*sizeof(HYPRE_Int)); CHECK_V_ERROR; tmpFill = (HYPRE_Int*)MALLOC_DH(m*sizeof(HYPRE_Int)); CHECK_V_ERROR; for (i=0; i<m; ++i) marker[i] = -1; /* working space for values */ for (i=0; i<m; ++i) work[i] = 0.0; /* printf_dh("====================== starting iluk_seq; level= %i\n\n", ctx->level); */ /*---------- main loop ----------*/ for (i=from; i<to; ++i) { HYPRE_Int row = n2o_row[i]; /* local row number */ HYPRE_Int globalRow = row+beg_row; /* global row number */ /*hypre_fprintf(logFile, "--------------------------------- localRow= %i\n", 1+i); */ if (debug) { hypre_fprintf(logFile, "ILU_seq ================================= starting local row: %i, (global= %i) level= %i\n", i+1, i+1+sg->beg_rowP[myid_dh], ctx->level); } EuclidGetRow(ctx->A, globalRow, &len, &CVAL, &AVAL); CHECK_V_ERROR; /* compute scaling value for row(i) */ if (ctx->isScaled) { compute_scaling_private(i, len, AVAL, ctx); CHECK_V_ERROR; } /* Compute symbolic factor for row(i); this also performs sparsification */ count = symbolic_row_private(i, list, marker, tmpFill, len, CVAL, AVAL, o2n_col, ctx, debug); CHECK_V_ERROR; /* Ensure adequate storage; reallocate, if necessary. */ if (idx + count > F->alloc) { Factor_dhReallocate(F, idx, count); CHECK_V_ERROR; SET_INFO("REALLOCATED from ilu_seq"); cval = F->cval; fill = F->fill; aval = F->aval; } /* Copy factored symbolic row to permanent storage */ col = list[m]; while (count--) { cval[idx] = col; fill[idx] = tmpFill[col]; ++idx; /*hypre_fprintf(logFile, " col= %i\n", 1+col); */ col = list[col]; } /* add row-pointer to start of next row. */ rp[i+1] = idx; /* Insert pointer to diagonal */ temp = rp[i]; while (cval[temp] != i) ++temp; diag[i] = temp; /*hypre_fprintf(logFile, " diag[i]= %i\n", diag); */ /* compute numeric factor for current row */ numeric_row_private(i, len, CVAL, AVAL, work, o2n_col, ctx, debug); CHECK_V_ERROR EuclidRestoreRow(ctx->A, globalRow, &len, &CVAL, &AVAL); CHECK_V_ERROR; /* Copy factored numeric row to permanent storage, and re-zero work vector */ if (debug) { hypre_fprintf(logFile, "ILU_seq: "); for (j=rp[i]; j<rp[i+1]; ++j) { col = cval[j]; aval[j] = work[col]; work[col] = 0.0; hypre_fprintf(logFile, "%i,%i,%g ; ", 1+cval[j], fill[j], aval[j]); fflush(logFile); } hypre_fprintf(logFile, "\n"); } else { for (j=rp[i]; j<rp[i+1]; ++j) { col = cval[j]; aval[j] = work[col]; work[col] = 0.0; } } /* check for zero diagonal */ if (! aval[diag[i]]) { hypre_sprintf(msgBuf_dh, "zero diagonal in local row %i", i+1); SET_V_ERROR(msgBuf_dh); } } FREE_DH(list); CHECK_V_ERROR; FREE_DH(tmpFill); CHECK_V_ERROR; FREE_DH(marker); CHECK_V_ERROR; /* adjust column indices back to global */ if (beg_rowP) { HYPRE_Int start = rp[from]; HYPRE_Int stop = rp[to]; for (i=start; i<stop; ++i) cval[i] += beg_rowP; } /* for debugging: this is so the Print methods will work, even if F hasn't been fully factored */ for (i=to+1; i<m; ++i) rp[i] = 0; END_FUNC_DH }
void ilut_seq(Euclid_dh ctx) { START_FUNC_DH HYPRE_Int *rp, *cval, *diag, *CVAL; HYPRE_Int i, len, count, col, idx = 0; HYPRE_Int *list, *marker; HYPRE_Int temp, m, from, to; HYPRE_Int *n2o_row, *o2n_col, beg_row, beg_rowP; double *AVAL, droptol; REAL_DH *work, *aval, val; Factor_dh F = ctx->F; SubdomainGraph_dh sg = ctx->sg; bool debug = false; if (logFile != NULL && Parser_dhHasSwitch(parser_dh, "-debug_ilu")) debug = true; m = F->m; rp = F->rp; cval = F->cval; diag = F->diag; aval = F->aval; work = ctx->work; from = ctx->from; to = ctx->to; count = rp[from]; droptol = ctx->droptol; if (sg == NULL) { SET_V_ERROR("subdomain graph is NULL"); } n2o_row = ctx->sg->n2o_row; o2n_col = ctx->sg->o2n_col; beg_row = ctx->sg->beg_row[myid_dh]; beg_rowP = ctx->sg->beg_rowP[myid_dh]; /* allocate and initialize working space */ list = (HYPRE_Int*)MALLOC_DH((m+1)*sizeof(HYPRE_Int)); CHECK_V_ERROR; marker = (HYPRE_Int*)MALLOC_DH(m*sizeof(HYPRE_Int)); CHECK_V_ERROR; for (i=0; i<m; ++i) marker[i] = -1; rp[0] = 0; /* working space for values */ for (i=0; i<m; ++i) work[i] = 0.0; /* ----- main loop start ----- */ for (i=from; i<to; ++i) { HYPRE_Int row = n2o_row[i]; /* local row number */ HYPRE_Int globalRow = row + beg_row; /* global row number */ EuclidGetRow(ctx->A, globalRow, &len, &CVAL, &AVAL); CHECK_V_ERROR; /* compute scaling value for row(i) */ compute_scaling_private(i, len, AVAL, ctx); CHECK_V_ERROR; /* compute factor for row i */ count = ilut_row_private(i, list, o2n_col, marker, len, CVAL, AVAL, work, ctx, debug); CHECK_V_ERROR; EuclidRestoreRow(ctx->A, globalRow, &len, &CVAL, &AVAL); CHECK_V_ERROR; /* Ensure adequate storage; reallocate, if necessary. */ if (idx + count > F->alloc) { Factor_dhReallocate(F, idx, count); CHECK_V_ERROR; SET_INFO("REALLOCATED from ilu_seq"); cval = F->cval; aval = F->aval; } /* Copy factored row to permanent storage, apply 2nd drop test, and re-zero work vector */ col = list[m]; while (count--) { val = work[col]; if (col == i || fabs(val) > droptol) { cval[idx] = col; aval[idx++] = val; work[col] = 0.0; } col = list[col]; } /* add row-pointer to start of next row. */ rp[i+1] = idx; /* Insert pointer to diagonal */ temp = rp[i]; while (cval[temp] != i) ++temp; diag[i] = temp; /* check for zero diagonal */ if (! aval[diag[i]]) { hypre_sprintf(msgBuf_dh, "zero diagonal in local row %i", i+1); SET_V_ERROR(msgBuf_dh); } } /* --------- main loop end --------- */ /* adjust column indices back to global */ if (beg_rowP) { HYPRE_Int start = rp[from]; HYPRE_Int stop = rp[to]; for (i=start; i<stop; ++i) cval[i] += beg_rowP; } FREE_DH(list); FREE_DH(marker); END_FUNC_DH }
void iluk_seq_block(Euclid_dh ctx) { START_FUNC_DH HYPRE_Int *rp, *cval, *diag; HYPRE_Int *CVAL; HYPRE_Int h, i, j, len, count, col, idx = 0; HYPRE_Int *list, *marker, *fill, *tmpFill; HYPRE_Int temp, m; HYPRE_Int *n2o_row, *o2n_col, *beg_rowP, *n2o_sub, blocks; HYPRE_Int *row_count, *dummy = NULL, dummy2[1]; double *AVAL; REAL_DH *work, *aval; Factor_dh F = ctx->F; SubdomainGraph_dh sg = ctx->sg; bool bj = false, constrained = false; HYPRE_Int discard = 0; HYPRE_Int gr = -1; /* globalRow */ bool debug = false; if (logFile != NULL && Parser_dhHasSwitch(parser_dh, "-debug_ilu")) debug = true; /*hypre_fprintf(stderr, "====================== starting iluk_seq_block; level= %i\n\n", ctx->level); */ if (!strcmp(ctx->algo_par, "bj")) bj = true; constrained = ! Parser_dhHasSwitch(parser_dh, "-unconstrained"); m = F->m; rp = F->rp; cval = F->cval; fill = F->fill; diag = F->diag; aval = F->aval; work = ctx->work; if (sg != NULL) { n2o_row = sg->n2o_row; o2n_col = sg->o2n_col; row_count = sg->row_count; /* beg_row = sg->beg_row ; */ beg_rowP = sg->beg_rowP; n2o_sub = sg->n2o_sub; blocks = sg->blocks; } else { dummy = (HYPRE_Int*)MALLOC_DH(m*sizeof(HYPRE_Int)); CHECK_V_ERROR; for (i=0; i<m; ++i) dummy[i] = i; n2o_row = dummy; o2n_col = dummy; dummy2[0] = m; row_count = dummy2; /* beg_row = 0; */ beg_rowP = dummy; n2o_sub = dummy; blocks = 1; } /* allocate and initialize working space */ list = (HYPRE_Int*)MALLOC_DH((m+1)*sizeof(HYPRE_Int)); CHECK_V_ERROR; marker = (HYPRE_Int*)MALLOC_DH(m*sizeof(HYPRE_Int)); CHECK_V_ERROR; tmpFill = (HYPRE_Int*)MALLOC_DH(m*sizeof(HYPRE_Int)); CHECK_V_ERROR; for (i=0; i<m; ++i) marker[i] = -1; /* working space for values */ for (i=0; i<m; ++i) work[i] = 0.0; /*---------- main loop ----------*/ for (h=0; h<blocks; ++h) { /* 1st and last row in current block, with respect to A */ HYPRE_Int curBlock = n2o_sub[h]; HYPRE_Int first_row = beg_rowP[curBlock]; HYPRE_Int end_row = first_row + row_count[curBlock]; if (debug) { hypre_fprintf(logFile, "\n\nILU_seq BLOCK: %i @@@@@@@@@@@@@@@ \n", curBlock); } for (i=first_row; i<end_row; ++i) { HYPRE_Int row = n2o_row[i]; ++gr; if (debug) { hypre_fprintf(logFile, "ILU_seq global: %i local: %i =================================\n", 1+gr, 1+i-first_row); } /*prinft("first_row= %i end_row= %i\n", first_row, end_row); */ EuclidGetRow(ctx->A, row, &len, &CVAL, &AVAL); CHECK_V_ERROR; /* compute scaling value for row(i) */ if (ctx->isScaled) { compute_scaling_private(i, len, AVAL, ctx); CHECK_V_ERROR; } /* Compute symbolic factor for row(i); this also performs sparsification */ count = symbolic_row_private(i, list, marker, tmpFill, len, CVAL, AVAL, o2n_col, ctx, debug); CHECK_V_ERROR; /* Ensure adequate storage; reallocate, if necessary. */ if (idx + count > F->alloc) { Factor_dhReallocate(F, idx, count); CHECK_V_ERROR; SET_INFO("REALLOCATED from ilu_seq"); cval = F->cval; fill = F->fill; aval = F->aval; } /* Copy factored symbolic row to permanent storage */ col = list[m]; while (count--) { /* constrained pilu */ if (constrained && !bj) { if (col >= first_row && col < end_row) { cval[idx] = col; fill[idx] = tmpFill[col]; ++idx; } else { if (check_constraint_private(ctx, curBlock, col)) { cval[idx] = col; fill[idx] = tmpFill[col]; ++idx; } else { ++discard; } } col = list[col]; } /* block jacobi case */ else if (bj) { if (col >= first_row && col < end_row) { cval[idx] = col; fill[idx] = tmpFill[col]; ++idx; } else { ++discard; } col = list[col]; } /* general case */ else { cval[idx] = col; fill[idx] = tmpFill[col]; ++idx; col = list[col]; } } /* add row-pointer to start of next row. */ rp[i+1] = idx; /* Insert pointer to diagonal */ temp = rp[i]; while (cval[temp] != i) ++temp; diag[i] = temp; /* compute numeric factor for current row */ numeric_row_private(i, len, CVAL, AVAL, work, o2n_col, ctx, debug); CHECK_V_ERROR EuclidRestoreRow(ctx->A, row, &len, &CVAL, &AVAL); CHECK_V_ERROR; /* Copy factored numeric row to permanent storage, and re-zero work vector */ if (debug) { hypre_fprintf(logFile, "ILU_seq: "); for (j=rp[i]; j<rp[i+1]; ++j) { col = cval[j]; aval[j] = work[col]; work[col] = 0.0; hypre_fprintf(logFile, "%i,%i,%g ; ", 1+cval[j], fill[j], aval[j]); } hypre_fprintf(logFile, "\n"); } /* normal operation */ else { for (j=rp[i]; j<rp[i+1]; ++j) { col = cval[j]; aval[j] = work[col]; work[col] = 0.0; } } /* check for zero diagonal */ if (! aval[diag[i]]) { hypre_sprintf(msgBuf_dh, "zero diagonal in local row %i", i+1); SET_V_ERROR(msgBuf_dh); } } } /* hypre_printf("bj= %i constrained= %i discarded= %i\n", bj, constrained, discard); */ if (dummy != NULL) { FREE_DH(dummy); CHECK_V_ERROR; } FREE_DH(list); CHECK_V_ERROR; FREE_DH(tmpFill); CHECK_V_ERROR; FREE_DH(marker); CHECK_V_ERROR; END_FUNC_DH }
void iluk_mpi_bj(Euclid_dh ctx) { START_FUNC_DH HYPRE_Int *rp, *cval, *diag; HYPRE_Int *CVAL; HYPRE_Int i, j, len, count, col, idx = 0; HYPRE_Int *list, *marker, *fill, *tmpFill; HYPRE_Int temp, m, from = ctx->from, to = ctx->to; HYPRE_Int *n2o_row, *o2n_col; HYPRE_Int first_row, last_row; double *AVAL; REAL_DH *work, *aval; Factor_dh F = ctx->F; SubdomainGraph_dh sg = ctx->sg; if (ctx->F == NULL) { SET_V_ERROR("ctx->F is NULL"); } if (ctx->F->rp == NULL) { SET_V_ERROR("ctx->F->rp is NULL"); } /* printf_dh("====================== starting iluk_mpi_bj; level= %i\n\n", ctx->level); */ m = F->m; rp = F->rp; cval = F->cval; fill = F->fill; diag = F->diag; aval = F->aval; work = ctx->work; n2o_row = sg->n2o_row; o2n_col = sg->o2n_col; /* allocate and initialize working space */ list = (HYPRE_Int*)MALLOC_DH((m+1)*sizeof(HYPRE_Int)); CHECK_V_ERROR; marker = (HYPRE_Int*)MALLOC_DH(m*sizeof(HYPRE_Int)); CHECK_V_ERROR; tmpFill = (HYPRE_Int*)MALLOC_DH(m*sizeof(HYPRE_Int)); CHECK_V_ERROR; for (i=0; i<m; ++i) { marker[i] = -1; work[i] = 0.0; } /*---------- main loop ----------*/ /* global numbers of first and last locally owned rows, with respect to A */ first_row = sg->beg_row[myid_dh]; last_row = first_row + sg->row_count[myid_dh]; for (i=from; i<to; ++i) { HYPRE_Int row = n2o_row[i]; /* local row number */ HYPRE_Int globalRow = row + first_row; /* global row number */ EuclidGetRow(ctx->A, globalRow, &len, &CVAL, &AVAL); CHECK_V_ERROR; /* compute scaling value for row(i) */ if (ctx->isScaled) { compute_scaling_private(i, len, AVAL, ctx); CHECK_V_ERROR; } /* Compute symbolic factor for row(i); this also performs sparsification */ count = symbolic_row_private(i, first_row, last_row, list, marker, tmpFill, len, CVAL, AVAL, o2n_col, ctx); CHECK_V_ERROR; /* Ensure adequate storage; reallocate, if necessary. */ if (idx + count > F->alloc) { Factor_dhReallocate(F, idx, count); CHECK_V_ERROR; SET_INFO("REALLOCATED from lu_mpi_bj"); cval = F->cval; fill = F->fill; aval = F->aval; } /* Copy factored symbolic row to permanent storage */ col = list[m]; while (count--) { cval[idx] = col; fill[idx] = tmpFill[col]; ++idx; col = list[col]; } /* add row-pointer to start of next row. */ rp[i+1] = idx; /* Insert pointer to diagonal */ temp = rp[i]; while (cval[temp] != i) ++temp; diag[i] = temp; /* compute numeric factor for current row */ numeric_row_private(i, first_row, last_row, len, CVAL, AVAL, work, o2n_col, ctx); CHECK_V_ERROR EuclidRestoreRow(ctx->A, globalRow, &len, &CVAL, &AVAL); CHECK_V_ERROR; /* Copy factored numeric row to permanent storage, and re-zero work vector */ for (j=rp[i]; j<rp[i+1]; ++j) { col = cval[j]; aval[j] = work[col]; work[col] = 0.0; } /* check for zero diagonal */ if (! aval[diag[i]]) { hypre_sprintf(msgBuf_dh, "zero diagonal in local row %i", i+1); SET_V_ERROR(msgBuf_dh); } } FREE_DH(list); CHECK_V_ERROR; FREE_DH(tmpFill); CHECK_V_ERROR; FREE_DH(marker); CHECK_V_ERROR; END_FUNC_DH }
HYPRE_Int main( HYPRE_Int argc, char *argv[] ) { HYPRE_Int arg_index; HYPRE_Int print_usage; HYPRE_Int build_matrix_arg_index; HYPRE_Int solver_id; HYPRE_Int ierr,i,j; HYPRE_Int num_iterations; HYPRE_ParCSRMatrix parcsr_A; HYPRE_Int num_procs, myid; HYPRE_Int local_row; HYPRE_Int time_index; MPI_Comm comm; HYPRE_Int M, N; HYPRE_Int first_local_row, last_local_row; HYPRE_Int first_local_col, last_local_col; HYPRE_Int size, *col_ind; HYPRE_Real *values; /* parameters for BoomerAMG */ HYPRE_Real strong_threshold; HYPRE_Int num_grid_sweeps; HYPRE_Real relax_weight; /* parameters for GMRES */ HYPRE_Int k_dim; char *paramString = new char[100]; /*----------------------------------------------------------- * Initialize some stuff *-----------------------------------------------------------*/ hypre_MPI_Init(&argc, &argv); hypre_MPI_Comm_size(hypre_MPI_COMM_WORLD, &num_procs ); hypre_MPI_Comm_rank(hypre_MPI_COMM_WORLD, &myid ); /*----------------------------------------------------------- * Set defaults *-----------------------------------------------------------*/ build_matrix_arg_index = argc; solver_id = 0; strong_threshold = 0.25; num_grid_sweeps = 2; relax_weight = 0.5; k_dim = 20; /*----------------------------------------------------------- * Parse command line *-----------------------------------------------------------*/ print_usage = 0; arg_index = 1; while ( (arg_index < argc) && (!print_usage) ) { if ( strcmp(argv[arg_index], "-solver") == 0 ) { arg_index++; solver_id = atoi(argv[arg_index++]); } else if ( strcmp(argv[arg_index], "-dbg") == 0 ) { arg_index++; atoi(argv[arg_index++]); } else if ( strcmp(argv[arg_index], "-help") == 0 ) { print_usage = 1; } else { arg_index++; } } /*----------------------------------------------------------- * Print usage info *-----------------------------------------------------------*/ if ( (print_usage) && (myid == 0) ) { hypre_printf("\n"); hypre_printf("Usage: %s [<options>]\n", argv[0]); hypre_printf("\n"); hypre_printf(" -solver <ID> : solver ID\n"); hypre_printf(" 0=DS-PCG 1=ParaSails-PCG \n"); hypre_printf(" 2=AMG-PCG 3=DS-GMRES \n"); hypre_printf(" 4=PILUT-GMRES 5=AMG-GMRES \n"); hypre_printf("\n"); hypre_printf(" -rlx <val> : relaxation type\n"); hypre_printf(" 0=Weighted Jacobi \n"); hypre_printf(" 1=Gauss-Seidel (very slow!) \n"); hypre_printf(" 3=Hybrid Jacobi/Gauss-Seidel \n"); hypre_printf("\n"); exit(1); } /*----------------------------------------------------------- * Print driver parameters *-----------------------------------------------------------*/ if (myid == 0) { hypre_printf("Running with these driver parameters:\n"); hypre_printf(" solver ID = %d\n", solver_id); } /*----------------------------------------------------------- * Set up matrix *-----------------------------------------------------------*/ strcpy(paramString, "LS Interface"); time_index = hypre_InitializeTiming(paramString); hypre_BeginTiming(time_index); BuildParLaplacian27pt(argc, argv, build_matrix_arg_index, &parcsr_A); /*----------------------------------------------------------- * Copy the parcsr matrix into the LSI through interface calls *-----------------------------------------------------------*/ ierr = HYPRE_ParCSRMatrixGetComm( parcsr_A, &comm ); ierr += HYPRE_ParCSRMatrixGetDims( parcsr_A, &M, &N ); ierr = HYPRE_ParCSRMatrixGetLocalRange( parcsr_A, &first_local_row, &last_local_row , &first_local_col, &last_local_col ); HYPRE_LinSysCore H(hypre_MPI_COMM_WORLD); HYPRE_Int numLocalEqns = last_local_row - first_local_row + 1; H.createMatricesAndVectors(M,first_local_row+1,numLocalEqns); HYPRE_Int index; HYPRE_Int *rowLengths = new HYPRE_Int[numLocalEqns]; HYPRE_Int **colIndices = new HYPRE_Int*[numLocalEqns]; local_row = 0; for (i=first_local_row; i<= last_local_row; i++) { ierr += HYPRE_ParCSRMatrixGetRow(parcsr_A,i,&size,&col_ind,&values ); rowLengths[local_row] = size; colIndices[local_row] = new HYPRE_Int[size]; for (j=0; j<size; j++) colIndices[local_row][j] = col_ind[j] + 1; local_row++; HYPRE_ParCSRMatrixRestoreRow(parcsr_A,i,&size,&col_ind,&values); } H.allocateMatrix(colIndices, rowLengths); delete [] rowLengths; for (i=0; i< numLocalEqns; i++) delete [] colIndices[i]; delete [] colIndices; HYPRE_Int *newColInd; for (i=first_local_row; i<= last_local_row; i++) { ierr += HYPRE_ParCSRMatrixGetRow(parcsr_A,i,&size,&col_ind,&values ); newColInd = new HYPRE_Int[size]; for (j=0; j<size; j++) newColInd[j] = col_ind[j] + 1; H.sumIntoSystemMatrix(i+1,size,(const HYPRE_Real*)values, (const HYPRE_Int*)newColInd); delete [] newColInd; ierr += HYPRE_ParCSRMatrixRestoreRow(parcsr_A,i,&size,&col_ind,&values); } H.matrixLoadComplete(); HYPRE_ParCSRMatrixDestroy(parcsr_A); /*----------------------------------------------------------- * Set up the RHS and initial guess *-----------------------------------------------------------*/ HYPRE_Real ddata=1.0; HYPRE_Int status; for (i=first_local_row; i<= last_local_row; i++) { index = i + 1; H.sumIntoRHSVector(1,(const HYPRE_Real*) &ddata, (const HYPRE_Int*) &index); } hypre_EndTiming(time_index); strcpy(paramString, "LS Interface"); hypre_PrintTiming(paramString, hypre_MPI_COMM_WORLD); hypre_FinalizeTiming(time_index); hypre_ClearTiming(); /*----------------------------------------------------------- * Solve the system using PCG *-----------------------------------------------------------*/ if ( solver_id == 0 ) { strcpy(paramString, "solver cg"); H.parameters(1, ¶mString); if (myid == 0) hypre_printf("Solver: DS-PCG\n"); strcpy(paramString, "preconditioner diagonal"); H.parameters(1, ¶mString); } else if ( solver_id == 1 ) { strcpy(paramString, "solver cg"); H.parameters(1, ¶mString); if (myid == 0) hypre_printf("Solver: ParaSails-PCG\n"); strcpy(paramString, "preconditioner parasails"); H.parameters(1, ¶mString); strcpy(paramString, "parasailsNlevels 1"); H.parameters(1, ¶mString); strcpy(paramString, "parasailsThreshold 0.1"); H.parameters(1, ¶mString); } else if ( solver_id == 2 ) { strcpy(paramString, "solver cg"); H.parameters(1, ¶mString); if (myid == 0) hypre_printf("Solver: AMG-PCG\n"); strcpy(paramString, "preconditioner boomeramg"); H.parameters(1, ¶mString); strcpy(paramString, "amgCoarsenType falgout"); H.parameters(1, ¶mString); hypre_sprintf(paramString, "amgStrongThreshold %e", strong_threshold); H.parameters(1, ¶mString); hypre_sprintf(paramString, "amgNumSweeps %d", num_grid_sweeps); H.parameters(1, ¶mString); strcpy(paramString, "amgRelaxType jacobi"); H.parameters(1, ¶mString); hypre_sprintf(paramString, "amgRelaxWeight %e", relax_weight); H.parameters(1, ¶mString); } else if ( solver_id == 3 ) { strcpy(paramString, "solver cg"); H.parameters(1, ¶mString); if (myid == 0) hypre_printf("Solver: Poly-PCG\n"); strcpy(paramString, "preconditioner poly"); H.parameters(1, ¶mString); strcpy(paramString, "polyOrder 9"); H.parameters(1, ¶mString); } else if ( solver_id == 4 ) { strcpy(paramString, "solver gmres"); H.parameters(1, ¶mString); hypre_sprintf(paramString, "gmresDim %d", k_dim); H.parameters(1, ¶mString); if (myid == 0) hypre_printf("Solver: DS-GMRES\n"); strcpy(paramString, "preconditioner diagonal"); H.parameters(1, ¶mString); } else if ( solver_id == 5 ) { strcpy(paramString, "solver gmres"); H.parameters(1, ¶mString); hypre_sprintf(paramString, "gmresDim %d", k_dim); H.parameters(1, ¶mString); if (myid == 0) hypre_printf("Solver: PILUT-GMRES\n"); strcpy(paramString, "preconditioner pilut"); H.parameters(1, ¶mString); strcpy(paramString, "pilutRowSize 0"); H.parameters(1, ¶mString); strcpy(paramString, "pilutDropTol 0.0"); H.parameters(1, ¶mString); } else if ( solver_id == 6 ) { strcpy(paramString, "solver gmres"); H.parameters(1, ¶mString); hypre_sprintf(paramString, "gmresDim %d", k_dim); H.parameters(1, ¶mString); if (myid == 0) hypre_printf("Solver: AMG-GMRES\n"); strcpy(paramString, "preconditioner boomeramg"); H.parameters(1, ¶mString); strcpy(paramString, "amgCoarsenType falgout"); H.parameters(1, ¶mString); hypre_sprintf(paramString, "amgStrongThreshold %e", strong_threshold); H.parameters(1, ¶mString); hypre_sprintf(paramString, "amgNumSweeps %d", num_grid_sweeps); H.parameters(1, ¶mString); strcpy(paramString, "amgRelaxType jacobi"); H.parameters(1, ¶mString); hypre_sprintf(paramString, "amgRelaxWeight %e", relax_weight); H.parameters(1, ¶mString); } else if ( solver_id == 7 ) { strcpy(paramString, "solver gmres"); H.parameters(1, ¶mString); hypre_sprintf(paramString, "gmresDim %d", k_dim); H.parameters(1, ¶mString); if (myid == 0) hypre_printf("Solver: DDILUT-GMRES\n"); strcpy(paramString, "preconditioner ddilut"); H.parameters(1, ¶mString); strcpy(paramString, "ddilutFillin 5.0"); H.parameters(1, ¶mString); strcpy(paramString, "ddilutDropTol 0.0"); H.parameters(1, ¶mString); } else if ( solver_id == 8 ) { strcpy(paramString, "solver gmres"); H.parameters(1, ¶mString); hypre_sprintf(paramString, "gmresDim %d", k_dim); H.parameters(1, ¶mString); if (myid == 0) hypre_printf("Solver: POLY-GMRES\n"); strcpy(paramString, "preconditioner poly"); H.parameters(1, ¶mString); strcpy(paramString, "polyOrder 5"); H.parameters(1, ¶mString); } strcpy(paramString, "Krylov Solve"); time_index = hypre_InitializeTiming(paramString); hypre_BeginTiming(time_index); H.launchSolver(status, num_iterations); hypre_EndTiming(time_index); strcpy(paramString, "Solve phase times"); hypre_PrintTiming(paramString, hypre_MPI_COMM_WORLD); hypre_FinalizeTiming(time_index); hypre_ClearTiming(); if (myid == 0) { hypre_printf("\n Iterations = %d\n", num_iterations); hypre_printf("\n"); } /*----------------------------------------------------------- * Finalize things *-----------------------------------------------------------*/ delete [] paramString; hypre_MPI_Finalize(); return (0); }
HYPRE_Int hypre_SysPFMGSolve( void *sys_pfmg_vdata, hypre_SStructMatrix *A_in, hypre_SStructVector *b_in, hypre_SStructVector *x_in ) { hypre_SysPFMGData *sys_pfmg_data = sys_pfmg_vdata; hypre_SStructPMatrix *A; hypre_SStructPVector *b; hypre_SStructPVector *x; double tol = (sys_pfmg_data -> tol); HYPRE_Int max_iter = (sys_pfmg_data -> max_iter); HYPRE_Int rel_change = (sys_pfmg_data -> rel_change); HYPRE_Int zero_guess = (sys_pfmg_data -> zero_guess); HYPRE_Int num_pre_relax = (sys_pfmg_data -> num_pre_relax); HYPRE_Int num_post_relax = (sys_pfmg_data -> num_post_relax); HYPRE_Int num_levels = (sys_pfmg_data -> num_levels); hypre_SStructPMatrix **A_l = (sys_pfmg_data -> A_l); hypre_SStructPMatrix **P_l = (sys_pfmg_data -> P_l); hypre_SStructPMatrix **RT_l = (sys_pfmg_data -> RT_l); hypre_SStructPVector **b_l = (sys_pfmg_data -> b_l); hypre_SStructPVector **x_l = (sys_pfmg_data -> x_l); hypre_SStructPVector **r_l = (sys_pfmg_data -> r_l); hypre_SStructPVector **e_l = (sys_pfmg_data -> e_l); void **relax_data_l = (sys_pfmg_data -> relax_data_l); void **matvec_data_l = (sys_pfmg_data -> matvec_data_l); void **restrict_data_l = (sys_pfmg_data -> restrict_data_l); void **interp_data_l = (sys_pfmg_data -> interp_data_l); HYPRE_Int logging = (sys_pfmg_data -> logging); double *norms = (sys_pfmg_data -> norms); double *rel_norms = (sys_pfmg_data -> rel_norms); HYPRE_Int *active_l = (sys_pfmg_data -> active_l); double b_dot_b, r_dot_r, eps; double e_dot_e, x_dot_x; HYPRE_Int i, l; HYPRE_Int ierr = 0; #if DEBUG char filename[255]; #endif /*----------------------------------------------------- * Initialize some things and deal with special cases *-----------------------------------------------------*/ hypre_BeginTiming(sys_pfmg_data -> time_index); /*----------------------------------------------------- * Refs to A,x,b (the PMatrix & PVectors within * the input SStructMatrix & SStructVectors) *-----------------------------------------------------*/ hypre_SStructPMatrixRef(hypre_SStructMatrixPMatrix(A_in, 0), &A); hypre_SStructPVectorRef(hypre_SStructVectorPVector(b_in, 0), &b); hypre_SStructPVectorRef(hypre_SStructVectorPVector(x_in, 0), &x); hypre_SStructPMatrixDestroy(A_l[0]); hypre_SStructPVectorDestroy(b_l[0]); hypre_SStructPVectorDestroy(x_l[0]); hypre_SStructPMatrixRef(A, &A_l[0]); hypre_SStructPVectorRef(b, &b_l[0]); hypre_SStructPVectorRef(x, &x_l[0]); (sys_pfmg_data -> num_iterations) = 0; /* if max_iter is zero, return */ if (max_iter == 0) { /* if using a zero initial guess, return zero */ if (zero_guess) { hypre_SStructPVectorSetConstantValues(x, 0.0); } hypre_EndTiming(sys_pfmg_data -> time_index); return ierr; } /* part of convergence check */ if (tol > 0.0) { /* eps = (tol^2) */ hypre_SStructPInnerProd(b_l[0], b_l[0], &b_dot_b); eps = tol*tol; /* if rhs is zero, return a zero solution */ if (b_dot_b == 0.0) { hypre_SStructPVectorSetConstantValues(x, 0.0); if (logging > 0) { norms[0] = 0.0; rel_norms[0] = 0.0; } hypre_EndTiming(sys_pfmg_data -> time_index); return ierr; } } /*----------------------------------------------------- * Do V-cycles: * For each index l, "fine" = l, "coarse" = (l+1) *-----------------------------------------------------*/ for (i = 0; i < max_iter; i++) { /*-------------------------------------------------- * Down cycle *--------------------------------------------------*/ /* fine grid pre-relaxation */ hypre_SysPFMGRelaxSetPreRelax(relax_data_l[0]); hypre_SysPFMGRelaxSetMaxIter(relax_data_l[0], num_pre_relax); hypre_SysPFMGRelaxSetZeroGuess(relax_data_l[0], zero_guess); hypre_SysPFMGRelax(relax_data_l[0], A_l[0], b_l[0], x_l[0]); zero_guess = 0; /* compute fine grid residual (b - Ax) */ hypre_SStructPCopy(b_l[0], r_l[0]); hypre_SStructPMatvecCompute(matvec_data_l[0], -1.0, A_l[0], x_l[0], 1.0, r_l[0]); /* convergence check */ if (tol > 0.0) { hypre_SStructPInnerProd(r_l[0], r_l[0], &r_dot_r); if (logging > 0) { norms[i] = sqrt(r_dot_r); if (b_dot_b > 0) rel_norms[i] = sqrt(r_dot_r/b_dot_b); else rel_norms[i] = 0.0; } /* always do at least 1 V-cycle */ if ((r_dot_r/b_dot_b < eps) && (i > 0)) { if (rel_change) { if ((e_dot_e/x_dot_x) < eps) break; } else { break; } } } if (num_levels > 1) { /* restrict fine grid residual */ hypre_SysSemiRestrict(restrict_data_l[0], RT_l[0], r_l[0], b_l[1]); #if DEBUG hypre_sprintf(filename, "zout_xdown.%02d", 0); hypre_SStructPVectorPrint(filename, x_l[0], 0); hypre_sprintf(filename, "zout_rdown.%02d", 0); hypre_SStructPVectorPrint(filename, r_l[0], 0); hypre_sprintf(filename, "zout_b.%02d", 1); hypre_SStructPVectorPrint(filename, b_l[1], 0); #endif for (l = 1; l <= (num_levels - 2); l++) { if (active_l[l]) { /* pre-relaxation */ hypre_SysPFMGRelaxSetPreRelax(relax_data_l[l]); hypre_SysPFMGRelaxSetMaxIter(relax_data_l[l], num_pre_relax); hypre_SysPFMGRelaxSetZeroGuess(relax_data_l[l], 1); hypre_SysPFMGRelax(relax_data_l[l], A_l[l], b_l[l], x_l[l]); /* compute residual (b - Ax) */ hypre_SStructPCopy(b_l[l], r_l[l]); hypre_SStructPMatvecCompute(matvec_data_l[l], -1.0, A_l[l], x_l[l], 1.0, r_l[l]); } else { /* inactive level, set x=0, so r=(b-Ax)=b */ hypre_SStructPVectorSetConstantValues(x_l[l], 0.0); hypre_SStructPCopy(b_l[l], r_l[l]); } /* restrict residual */ hypre_SysSemiRestrict(restrict_data_l[l], RT_l[l], r_l[l], b_l[l+1]); #if DEBUG hypre_sprintf(filename, "zout_xdown.%02d", l); hypre_SStructPVectorPrint(filename, x_l[l], 0); hypre_sprintf(filename, "zout_rdown.%02d", l); hypre_SStructPVectorPrint(filename, r_l[l], 0); hypre_sprintf(filename, "zout_b.%02d", l+1); hypre_SStructPVectorPrint(filename, b_l[l+1], 0); #endif } /*-------------------------------------------------- * Bottom *--------------------------------------------------*/ hypre_SysPFMGRelaxSetZeroGuess(relax_data_l[l], 1); hypre_SysPFMGRelax(relax_data_l[l], A_l[l], b_l[l], x_l[l]); #if DEBUG hypre_sprintf(filename, "zout_xbottom.%02d", l); hypre_SStructPVectorPrint(filename, x_l[l], 0); #endif /*-------------------------------------------------- * Up cycle *--------------------------------------------------*/ for (l = (num_levels - 2); l >= 1; l--) { /* interpolate error and correct (x = x + Pe_c) */ hypre_SysSemiInterp(interp_data_l[l], P_l[l], x_l[l+1], e_l[l]); hypre_SStructPAxpy(1.0, e_l[l], x_l[l]); #if DEBUG hypre_sprintf(filename, "zout_eup.%02d", l); hypre_SStructPVectorPrint(filename, e_l[l], 0); hypre_sprintf(filename, "zout_xup.%02d", l); hypre_SStructPVectorPrint(filename, x_l[l], 0); #endif if (active_l[l]) { /* post-relaxation */ hypre_SysPFMGRelaxSetPostRelax(relax_data_l[l]); hypre_SysPFMGRelaxSetMaxIter(relax_data_l[l], num_post_relax); hypre_SysPFMGRelaxSetZeroGuess(relax_data_l[l], 0); hypre_SysPFMGRelax(relax_data_l[l], A_l[l], b_l[l], x_l[l]); } } /* interpolate error and correct on fine grid (x = x + Pe_c) */ hypre_SysSemiInterp(interp_data_l[0], P_l[0], x_l[1], e_l[0]); hypre_SStructPAxpy(1.0, e_l[0], x_l[0]); #if DEBUG hypre_sprintf(filename, "zout_eup.%02d", 0); hypre_SStructPVectorPrint(filename, e_l[0], 0); hypre_sprintf(filename, "zout_xup.%02d", 0); hypre_SStructPVectorPrint(filename, x_l[0], 0); #endif } /* part of convergence check */ if ((tol > 0.0) && (rel_change)) { if (num_levels > 1) { hypre_SStructPInnerProd(e_l[0], e_l[0], &e_dot_e); hypre_SStructPInnerProd(x_l[0], x_l[0], &x_dot_x); } else { e_dot_e = 0.0; x_dot_x = 1.0; } } /* fine grid post-relaxation */ hypre_SysPFMGRelaxSetPostRelax(relax_data_l[0]); hypre_SysPFMGRelaxSetMaxIter(relax_data_l[0], num_post_relax); hypre_SysPFMGRelaxSetZeroGuess(relax_data_l[0], 0); hypre_SysPFMGRelax(relax_data_l[0], A_l[0], b_l[0], x_l[0]); (sys_pfmg_data -> num_iterations) = (i + 1); } /*----------------------------------------------------- * Destroy Refs to A,x,b (the PMatrix & PVectors within * the input SStructMatrix & SStructVectors). *-----------------------------------------------------*/ hypre_SStructPMatrixDestroy(A); hypre_SStructPVectorDestroy(x); hypre_SStructPVectorDestroy(b); hypre_EndTiming(sys_pfmg_data -> time_index); return ierr; }
HYPRE_Int hypre_ParVectorReadIJ( MPI_Comm comm, const char *filename, HYPRE_Int *base_j_ptr, hypre_ParVector **vector_ptr) { HYPRE_Int global_size; hypre_ParVector *vector; hypre_Vector *local_vector; double *local_data; HYPRE_Int *partitioning; HYPRE_Int base_j; HYPRE_Int myid, num_procs, i, j, J; char new_filename[255]; FILE *file; hypre_MPI_Comm_size(comm, &num_procs); hypre_MPI_Comm_rank(comm, &myid); hypre_sprintf(new_filename,"%s.%05d", filename, myid); if ((file = fopen(new_filename, "r")) == NULL) { hypre_printf("Error: can't open output file %s\n", new_filename); hypre_error(HYPRE_ERROR_GENERIC); return hypre_error_flag; } hypre_fscanf(file, "%d", &global_size); #ifdef HYPRE_NO_GLOBAL_PARTITION /* this may need to be changed so that the base is available in the file! */ partitioning = hypre_CTAlloc(HYPRE_Int,2); hypre_fscanf(file, "%d", partitioning); for (i = 0; i < 2; i++) { hypre_fscanf(file, "%d", partitioning+i); } #else partitioning = hypre_CTAlloc(HYPRE_Int,num_procs+1); hypre_fscanf(file, "%d", partitioning); for (i = 1; i <= num_procs; i++) { hypre_fscanf(file, "%d", partitioning+i); partitioning[i] -= partitioning[0]; } base_j = partitioning[0]; partitioning[0] = 0; #endif vector = hypre_ParVectorCreate(comm, global_size, partitioning); hypre_ParVectorInitialize(vector); local_vector = hypre_ParVectorLocalVector(vector); local_data = hypre_VectorData(local_vector); #ifdef HYPRE_NO_GLOBAL_PARTITION for (j = 0; j < partitioning[1] - partitioning[0]; j++) #else for (j = 0; j < partitioning[myid+1] - partitioning[myid]; j++) #endif { hypre_fscanf(file, "%d %le", &J, local_data + j); } fclose(file); *base_j_ptr = base_j; *vector_ptr = vector; /* multivector code not written yet >>> */ hypre_assert( hypre_ParVectorNumVectors(vector) == 1 ); if ( hypre_ParVectorNumVectors(vector) != 1 ) hypre_error(HYPRE_ERROR_GENERIC); return hypre_error_flag; }
HYPRE_Int hypre_ParVectorPrintIJ( hypre_ParVector *vector, HYPRE_Int base_j, const char *filename ) { MPI_Comm comm; HYPRE_Int global_size; HYPRE_Int *partitioning; double *local_data; HYPRE_Int myid, num_procs, i, j, part0; char new_filename[255]; FILE *file; if (!vector) { hypre_error_in_arg(1); return hypre_error_flag; } comm = hypre_ParVectorComm(vector); global_size = hypre_ParVectorGlobalSize(vector); partitioning = hypre_ParVectorPartitioning(vector); /* multivector code not written yet >>> */ hypre_assert( hypre_ParVectorNumVectors(vector) == 1 ); if ( hypre_ParVectorNumVectors(vector) != 1 ) hypre_error_in_arg(1); hypre_MPI_Comm_rank(comm, &myid); hypre_MPI_Comm_size(comm, &num_procs); hypre_sprintf(new_filename,"%s.%05d", filename, myid); if ((file = fopen(new_filename, "w")) == NULL) { hypre_printf("Error: can't open output file %s\n", new_filename); hypre_error_in_arg(3); return hypre_error_flag; } local_data = hypre_VectorData(hypre_ParVectorLocalVector(vector)); hypre_fprintf(file, "%d \n", global_size); #ifdef HYPRE_NO_GLOBAL_PARTITION for (i=0; i <= 2; i++) #else for (i=0; i <= num_procs; i++) #endif { hypre_fprintf(file, "%d \n", partitioning[i] + base_j); } #ifdef HYPRE_NO_GLOBAL_PARTITION part0 = partitioning[0]; for (j = part0; j < partitioning[1]; j++) #else part0 = partitioning[myid]; for (j = part0; j < partitioning[myid+1]; j++) #endif { hypre_fprintf(file, "%d %.14e\n", j + base_j, local_data[j-part0]); } fclose(file); return hypre_error_flag; }