HYPRE_Int hypre_IJVectorZeroValues( HYPRE_IJVector vector ) { hypre_IJVector *vec = (hypre_IJVector *) vector; if (vec == NULL) { hypre_printf("Vector variable is NULL -- hypre_IJVectorZeroValues\n"); exit(1); } /* if ( hypre_IJVectorObjectType(vec) == HYPRE_PETSC ) return( hypre_IJVectorZeroValuesPETSc(vec) ); else if ( hypre_IJVectorObjectType(vec) == HYPRE_ISIS ) return( hypre_IJVectorZeroValuesISIS(vec) ); else */ if ( hypre_IJVectorObjectType(vec) == HYPRE_PARCSR ) return( hypre_IJVectorZeroValuesPar(vec) ); else { hypre_printf("Unrecognized object type -- hypre_IJVectorZeroValues\n"); exit(1); } return -99; }
HYPRE_Int hypre_SparseMSGPrintLogging( void *smsg_vdata, HYPRE_Int myid ) { hypre_SparseMSGData *smsg_data = smsg_vdata; HYPRE_Int ierr = 0; HYPRE_Int i; HYPRE_Int num_iterations = (smsg_data -> num_iterations); HYPRE_Int logging = (smsg_data -> logging); HYPRE_Int print_level = (smsg_data -> print_level); double *norms = (smsg_data -> norms); double *rel_norms = (smsg_data -> rel_norms); if (myid == 0) { if (print_level > 0) { if (logging > 0) { for (i = 0; i < num_iterations; i++) { hypre_printf("Residual norm[%d] = %e ",i,norms[i]); hypre_printf("Relative residual norm[%d] = %e\n",i,rel_norms[i]); } } } } return ierr; }
HYPRE_Int hypre_SysPFMGPrintLogging( void *sys_pfmg_vdata, HYPRE_Int myid) { hypre_SysPFMGData *sys_pfmg_data = sys_pfmg_vdata; HYPRE_Int i; HYPRE_Int num_iterations = (sys_pfmg_data -> num_iterations); HYPRE_Int logging = (sys_pfmg_data -> logging); HYPRE_Int print_level = (sys_pfmg_data -> print_level); HYPRE_Real *norms = (sys_pfmg_data -> norms); HYPRE_Real *rel_norms = (sys_pfmg_data -> rel_norms); if (myid == 0) { if (print_level > 0 ) { if (logging > 0) { for (i = 0; i < num_iterations; i++) { hypre_printf("Residual norm[%d] = %e ",i,norms[i]); hypre_printf("Relative residual norm[%d] = %e\n",i,rel_norms[i]); } } } } return hypre_error_flag; }
/************************************************************************* * This function prints an (idx, val) pair **************************************************************************/ void hypre_PrintIdxVal(HYPRE_Int n, HYPRE_Int *idx, double *val) { HYPRE_Int i; hypre_printf("%3d ", n); for (i=0; i<n; i++) hypre_printf("(%3d, %3.1e) ", idx[i], val[i]); hypre_printf("\n"); }
HYPRE_Int update_entry(HYPRE_Int weight, HYPRE_Int *weight_max, HYPRE_Int *previous, HYPRE_Int *next, HYPRE_Int *first, HYPRE_Int *last, HYPRE_Int head, HYPRE_Int tail, HYPRE_Int i) { HYPRE_Int ierr = 0, weight0; if (previous[i] != head) next[previous[i]] = next[i]; previous[next[i]] = previous[i]; if (first[weight] == tail) { if (weight <= weight_max[0]) { hypre_printf("ERROR IN UPDATE_ENTRY: ===================\n"); hypre_printf("weight: %d, weight_max: %d\n", weight, weight_max[0]); return -1; } for (weight0=weight_max[0]+1; weight0 <= weight; weight0++) { first[weight0] = i; /* hypre_printf("create first[%d] = %d\n", weight0, i); */ } previous[i] = previous[tail]; next[i] = tail; next[previous[tail]] = i; previous[tail] = i; } else /* first[weight] already exists: =====================*/ { previous[i] = previous[first[weight]]; next[i] = first[weight]; if (previous[first[weight]] != head) next[previous[first[weight]]] = i; previous[first[weight]] = i; for (weight0=1; weight0 <= weight; weight0++) if (first[weight0] == first[weight]) first[weight0] = i; } return ierr; }
HYPRE_Int AmgCGCBoundaryFix (hypre_ParCSRMatrix *S,HYPRE_Int *CF_marker,HYPRE_Int *CF_marker_offd) /* Checks whether an interpolation is possible for a fine grid point with strong couplings. * Required after CGC coarsening * ======================================================================================== * S : the strength matrix * CF_marker, CF_marker_offd : the coarse/fine markers * ========================================================================================*/ { HYPRE_Int mpirank,i,j,has_c_pt,ierr=0; hypre_CSRMatrix *S_diag = hypre_ParCSRMatrixDiag (S); hypre_CSRMatrix *S_offd = hypre_ParCSRMatrixOffd (S); HYPRE_Int *S_i = hypre_CSRMatrixI(S_diag); HYPRE_Int *S_j = hypre_CSRMatrixJ(S_diag); HYPRE_Int *S_offd_i = hypre_CSRMatrixI(S_offd); HYPRE_Int *S_offd_j = NULL; HYPRE_Int num_variables = hypre_CSRMatrixNumRows (S_diag); HYPRE_Int num_cols_offd = hypre_CSRMatrixNumCols (S_offd); HYPRE_Int added_cpts=0; MPI_Comm comm = hypre_ParCSRMatrixComm(S); hypre_MPI_Comm_rank (comm,&mpirank); if (num_cols_offd) { S_offd_j = hypre_CSRMatrixJ(S_offd); } for (i=0;i<num_variables;i++) { if (S_offd_i[i]==S_offd_i[i+1] || CF_marker[i] == C_PT) continue; has_c_pt=0; /* fine grid point with strong connections across the boundary */ for (j=S_i[i];j<S_i[i+1];j++) if (CF_marker[S_j[j]] == C_PT) {has_c_pt=1; break;} if (has_c_pt) continue; for (j=S_offd_i[i];j<S_offd_i[i+1];j++) if (CF_marker_offd[S_offd_j[j]] == C_PT) {has_c_pt=1; break;} if (has_c_pt) continue; /* all points i is strongly coupled to are fine: make i C_PT */ CF_marker[i] = C_PT; #if 0 hypre_printf ("Processor %d: added point %d in AmgCGCBoundaryFix\n",mpirank,i); #endif added_cpts++; } #if 0 if (added_cpts) hypre_printf ("Processor %d: added %d points in AmgCGCBoundaryFix\n",mpirank,added_cpts); fflush(stdout); #endif return(ierr); }
void StoredRowsPut(StoredRows *p, HYPRE_Int index, HYPRE_Int len, HYPRE_Int *ind, HYPRE_Real *val) { HYPRE_Int i = index - p->num_loc; /* Reallocate if necessary */ if (i >= p->size) { HYPRE_Int j; HYPRE_Int newsize; newsize = i*2; #ifdef PARASAILS_DEBUG hypre_printf("StoredRows resize %d\n", newsize); #endif p->len = (HYPRE_Int *) realloc(p->len, newsize * sizeof(HYPRE_Int)); p->ind = (HYPRE_Int **) realloc(p->ind, newsize * sizeof(HYPRE_Int *)); p->val = (HYPRE_Real **) realloc(p->val, newsize * sizeof(HYPRE_Real *)); /* set lengths to zero */ for (j=p->size; j<newsize; j++) p->len[j] = 0; p->size = newsize; } /* check that row has not been put already */ assert(p->len[i] == 0); p->len[i] = len; p->ind[i] = ind; p->val[i] = val; p->count++; }
/************************************************************************* * This function prints a vector on each processor **************************************************************************/ void hypre_PrintVector(HYPRE_Int *v, HYPRE_Int n, char *msg, hypre_PilutSolverGlobals *globals) { HYPRE_Int i, penum; for (penum=0; penum<npes; penum++) { if (mype == penum) { hypre_printf("PE %d %s: ", mype, msg); for (i=0; i<n; i++) hypre_printf("%d ", v[i]); hypre_printf("\n"); } hypre_MPI_Barrier( pilut_comm ); } }
/************************************************************************* * This function prints checksums for some arrays of the LDU struct **************************************************************************/ hypre_longint hypre_LDU_Checksum(const FactorMatType *ldu, hypre_PilutSolverGlobals *globals) { HYPRE_Int i, j; hypre_ulongint lisum=0, ldsum=0, uisum=0, udsum=0, dsum=0; static HYPRE_Int numChk = 0; if (ldu->lsrowptr == NULL || ldu->lerowptr == NULL || ldu->lcolind == NULL || ldu->lvalues == NULL || ldu->usrowptr == NULL || ldu->uerowptr == NULL || ldu->ucolind == NULL || ldu->uvalues == NULL || ldu->dvalues == NULL || ldu->nrm2s == NULL) { hypre_printf("PE %d [S%3d] LDU check -- not initializied\n", mype, numChk); fflush(stdout); return 0; } for (i=0; i<lnrows; i++) { for (j=ldu->lsrowptr[i]; j<ldu->lerowptr[i]; j++) { lisum += ldu->lcolind[j]; ldsum += (hypre_longint)ldu->lvalues[j]; } for (j=ldu->usrowptr[i]; j<ldu->uerowptr[i]; j++) { uisum += ldu->ucolind[j]; udsum += (hypre_longint)ldu->uvalues[j]; } if (ldu->usrowptr[i] < ldu->uerowptr[i]) dsum += (hypre_longint)ldu->dvalues[i]; } hypre_printf("PE %d [S%3d] LDU check [%16lx %16lx] [%16lx] [%16lx %16lx]\n", mype, numChk, lisum, ldsum, dsum, uisum, udsum); fflush(stdout); hypre_FP_Checksum(ldu->nrm2s, lnrows, "2-norms", numChk, globals); return 1; }
char *MemAlloc(Mem *m, HYPRE_Int size) { HYPRE_Int req; char *p; /* Align on 16-byte boundary */ size = ((size + 15) / 16) * 16; if (m->bytes_left < size) { /* Allocate a new block */ if (m->num_blocks+1 > MEM_MAXBLOCKS) { hypre_printf("MemAlloc: max number of blocks %d exceeded.\n", MEM_MAXBLOCKS); PARASAILS_EXIT; } /* Size of requested block */ req = MAX(size, MEM_BLOCKSIZE); m->avail = (char *) malloc(req); if (m->avail == NULL) { hypre_printf("MemAlloc: request for %d bytes failed.\n", req); PARASAILS_EXIT; } m->blocks[m->num_blocks] = m->avail; m->num_blocks++; m->bytes_left = req; m->total_bytes += size; m->bytes_alloc += req; if (req > MEM_BLOCKSIZE) m->num_over++; } p = m->avail; m->avail += size; m->bytes_left -= size; m->total_bytes += size; return p; }
/****************************************************************************** * * hypre_IJVectorInitializePar * * initializes ParVector of IJVectorPar * *****************************************************************************/ HYPRE_Int hypre_IJVectorInitializePar(hypre_IJVector *vector) { hypre_ParVector *par_vector = hypre_IJVectorObject(vector); hypre_AuxParVector *aux_vector = hypre_IJVectorTranslator(vector); HYPRE_Int *partitioning = hypre_ParVectorPartitioning(par_vector); hypre_Vector *local_vector = hypre_ParVectorLocalVector(par_vector); HYPRE_Int my_id; HYPRE_Int print_level = hypre_IJVectorPrintLevel(vector); MPI_Comm comm = hypre_IJVectorComm(vector); hypre_MPI_Comm_rank(comm,&my_id); if (!partitioning) { if (print_level) { hypre_printf("No ParVector partitioning for initialization -- "); hypre_printf("hypre_IJVectorInitializePar\n"); } hypre_error_in_arg(1); } #ifdef HYPRE_NO_GLOBAL_PARTITION hypre_VectorSize(local_vector) = partitioning[1] - partitioning[0]; #else hypre_VectorSize(local_vector) = partitioning[my_id+1] - partitioning[my_id]; #endif hypre_ParVectorInitialize(par_vector); if (!aux_vector) { hypre_AuxParVectorCreate(&aux_vector); hypre_IJVectorTranslator(vector) = aux_vector; } hypre_AuxParVectorInitialize(aux_vector); return hypre_error_flag; }
HYPRE_Int MH_Send(void* buf, hypre_uint count, HYPRE_Int dest, HYPRE_Int mid, MPI_Comm comm ) { HYPRE_Int my_id; HYPRE_Int retcode = hypre_MPI_Send( buf, (HYPRE_Int) count, hypre_MPI_BYTE, dest, mid, comm); if ( retcode != 0 ) { hypre_MPI_Comm_rank(comm, &my_id); hypre_printf("%d : MH_Send warning : retcode = %d\n", my_id, retcode); } return 0; }
/************************************************************************* * This function prints checksums for each array of the rmat struct **************************************************************************/ hypre_longint hypre_RMat_Checksum(const ReduceMatType *rmat, hypre_PilutSolverGlobals *globals) { HYPRE_Int i; static HYPRE_Int numChk = 0; /* for safety */ if ( rmat == NULL || rmat->rmat_rnz == NULL || rmat->rmat_rrowlen == NULL || rmat->rmat_rcolind == NULL || rmat->rmat_rvalues == NULL ) { hypre_printf("PE %d [r%3d] rmat checksum -- not initializied\n", mype, numChk); fflush(stdout); numChk++; return 0; } /* print ints */ hypre_printf("PE %d [r%3d] rmat checksum -- ndone %d ntogo %d nlevel %d\n", mype, numChk, rmat->rmat_ndone, rmat->rmat_ntogo, rmat->rmat_nlevel); fflush(stdout); /* print checksums for each array */ hypre_IDX_Checksum(rmat->rmat_rnz, rmat->rmat_ntogo, "rmat->rmat_rnz", numChk, globals); hypre_IDX_Checksum(rmat->rmat_rrowlen, rmat->rmat_ntogo, "rmat->rmat_rrowlen", numChk, globals); for (i=0; i<rmat->rmat_ntogo; i++) { hypre_IDX_Checksum(rmat->rmat_rcolind[i], rmat->rmat_rrowlen[i], "rmat->rmat_rcolind", i, globals); hypre_FP_Checksum(rmat->rmat_rvalues[i], rmat->rmat_rrowlen[i], "rmat->rmat_rvalues", i, globals); } return 1; }
HYPRE_Int MH_Irecv(void* buf, hypre_uint count, HYPRE_Int *src, HYPRE_Int *mid, MPI_Comm comm, hypre_MPI_Request *request ) { HYPRE_Int my_id, lsrc, retcode; if ( *src < 0 ) lsrc = hypre_MPI_ANY_SOURCE; else lsrc = (*src); retcode = hypre_MPI_Irecv( buf, (HYPRE_Int) count, hypre_MPI_BYTE, lsrc, *mid, comm, request); if ( retcode != 0 ) { hypre_MPI_Comm_rank(comm, &my_id); hypre_printf("%d : MH_Irecv warning : retcode = %d\n", my_id, retcode); } return 0; }
HYPRE_Int hypre_IJVectorDistribute( HYPRE_IJVector vector, const HYPRE_Int *vec_starts ) { hypre_IJVector *vec = (hypre_IJVector *) vector; if (vec == NULL) { hypre_printf("Vector variable is NULL -- hypre_IJVectorDistribute\n"); exit(1); } if ( hypre_IJVectorObjectType(vec) == HYPRE_PARCSR ) return( hypre_IJVectorDistributePar(vec, vec_starts) ); else { hypre_printf("Unrecognized object type -- hypre_IJVectorDistribute\n"); exit(1); } return -99; }
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_ParCSRMLSetBGSBlockSize( HYPRE_Solver solver, HYPRE_Int size ) { MH_Link *link = (MH_Link *) solver; if ( size < 0 ) { hypre_printf("HYPRE_ParCSRMLSetBGSBlockSize error : reset to 1.\n"); link->BGS_blocksize = 1; } else { link->BGS_blocksize = size; } return( 0 ); }
HYPRE_Int HYPRE_ParCSRMLSetPostSmoother( HYPRE_Solver solver, HYPRE_Int smoother_type ) { MH_Link *link = (MH_Link *) solver; if ( smoother_type < 0 || smoother_type > 4 ) { hypre_printf("HYPRE_ParCSRMLSetPostSmoother error : set to Jacobi.\n"); link->post = 0; } else { link->post = smoother_type; } return( 0 ); }
HYPRE_Int HYPRE_ParCSRMLSetNumPostSmoothings( HYPRE_Solver solver, HYPRE_Int num_sweeps ) { MH_Link *link = (MH_Link *) solver; if ( num_sweeps < 0 ) { hypre_printf("HYPRE_ParCSRMLSetNumPostSmoothings error : reset to 0.\n"); link->post_sweeps = 0; } else { link->post_sweeps = num_sweeps; } return( 0 ); }
HYPRE_Int HYPRE_ParCSRMLSetDampingFactor( HYPRE_Solver solver, double factor ) { MH_Link *link = (MH_Link *) solver; if ( factor < 0.0 || factor > 1.0 ) { hypre_printf("HYPRE_ParCSRMLSetDampingFactor error : set to 0.5.\n"); link->jacobi_wt = 0.5; } else { link->jacobi_wt = factor; } return( 0 ); }
HYPRE_Int MH_Wait(void* buf, hypre_uint count, HYPRE_Int *src, HYPRE_Int *mid, MPI_Comm comm, hypre_MPI_Request *request ) { hypre_MPI_Status status; HYPRE_Int my_id, incount, retcode; retcode = hypre_MPI_Wait( request, &status ); if ( retcode != 0 ) { hypre_MPI_Comm_rank(comm, &my_id); hypre_printf("%d : MH_Wait warning : retcode = %d\n", my_id, retcode); } hypre_MPI_Get_count(&status, hypre_MPI_BYTE, &incount); if ( *src < 0 ) *src = status.hypre_MPI_SOURCE; return incount; }
HYPRE_Int HYPRE_ParCSRMLSetStrongThreshold(HYPRE_Solver solver, double strong_threshold) { MH_Link *link = (MH_Link *) solver; if ( strong_threshold < 0.0 ) { hypre_printf("HYPRE_ParCSRMLSetStrongThreshold error : reset to 0.\n"); link->ag_threshold = 0.0; } else { link->ag_threshold = strong_threshold; } return( 0 ); }
static void balance_info(MPI_Comm comm, Matrix *mat) { HYPRE_Int mype, num_local, i, total; hypre_MPI_Comm_rank(comm, &mype); num_local = mat->end_row - mat->beg_row + 1; /* compute number of nonzeros on local matrix */ total = 0; for (i=0; i<num_local; i++) total += mat->lens[i]; /* each processor prints out its own info */ hypre_printf("%4d: nrows %d, nnz %d, send %d (%d), recv %d (%d)\n", mype, num_local, total, mat->num_send, mat->sendlen, mat->num_recv, mat->recvlen); }
HYPRE_Int main( HYPRE_Int argc, char *argv[] ) { hypre_ParCSRBooleanMatrix *A; hypre_ParCSRBooleanMatrix *C; hypre_CSRBooleanMatrix *As; HYPRE_Int *row_starts, *col_starts; HYPRE_Int num_procs, my_id; /* Initialize MPI */ hypre_MPI_Init(&argc, &argv); hypre_MPI_Comm_size(hypre_MPI_COMM_WORLD,&num_procs); hypre_MPI_Comm_rank(hypre_MPI_COMM_WORLD,&my_id); row_starts = NULL; col_starts = NULL; if (my_id == 0) { As = hypre_CSRBooleanMatrixRead("inpr"); hypre_printf(" read input A\n"); } A = hypre_CSRBooleanMatrixToParCSRBooleanMatrix(hypre_MPI_COMM_WORLD, As, row_starts, col_starts); row_starts = hypre_ParCSRBooleanMatrix_Get_RowStarts(A); col_starts = hypre_ParCSRBooleanMatrix_Get_ColStarts(A); hypre_ParCSRBooleanMatrixPrint(A, "echo_A" ); hypre_ParCSRBooleanMatrixPrintIJ(A, "echo_AIJ" ); C = hypre_ParBooleanAAt( A ); hypre_ParCSRBooleanMatrixPrint(C, "result"); hypre_ParCSRBooleanMatrixPrintIJ(C, "resultIJ"); if (my_id == 0) { hypre_CSRBooleanMatrixDestroy(As); } hypre_ParCSRBooleanMatrixDestroy(A); hypre_ParCSRBooleanMatrixDestroy(C); hypre_MPI_Finalize(); return 0; }
/************************************************************************* * This function prints a checksum for an HYPRE_Int (HYPRE_Int) array **************************************************************************/ hypre_longint hypre_INT_Checksum(const HYPRE_Int *v, HYPRE_Int len, const char *msg, HYPRE_Int tag, hypre_PilutSolverGlobals *globals) { static HYPRE_Int numChk = 0; HYPRE_Int i; hypre_ulongint sum = 0; for (i=0; i<len; i++) sum += v[i] * i; hypre_printf("PE %d [d%3d] %15s/%3d chk: %16lx [len %4d]\n", mype, numChk, msg, tag, sum, len); fflush(stdout); numChk++; return sum; }
/* Subroutine */ HYPRE_Int hypre_xerbla_(const char *srname, integer *info) { /* -- LAPACK auxiliary routine (version 2.0) -- Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., Courant Institute, Argonne National Lab, and Rice University September 30, 1994 Purpose ======= XERBLA is an error handler for the LAPACK routines. It is called by an LAPACK routine if an input parameter has an invalid value. A message is printed and execution stops. Installers may consider modifying the STOP statement in order to call system-specific exception-handling facilities. Arguments ========= SRNAME (input) CHARACTER*6 The name of the routine which called XERBLA. INFO (input) INTEGER The position of the invalid parameter in the parameter list of the calling routine. ===================================================================== */ hypre_printf("** On entry to %6s, parameter number %2i had an illegal value\n", srname, *info); /* End of XERBLA */ return 0; } /* hypre_xerbla_ */
/****************************************************************************** * * hypre_IJVectorDistributePar * * takes an IJVector generated for one processor and distributes it * across many processors according to vec_starts, * if vec_starts is NULL, it distributes them evenly? * *****************************************************************************/ HYPRE_Int hypre_IJVectorDistributePar(hypre_IJVector *vector, const HYPRE_Int *vec_starts) { hypre_ParVector *old_vector = hypre_IJVectorObject(vector); hypre_ParVector *par_vector; HYPRE_Int print_level = hypre_IJVectorPrintLevel(vector); if (!old_vector) { if (print_level) { hypre_printf("old_vector == NULL -- "); hypre_printf("hypre_IJVectorDistributePar\n"); hypre_printf("**** Vector storage is either unallocated or orphaned ****\n"); } hypre_error_in_arg(1); } par_vector = hypre_VectorToParVector(hypre_ParVectorComm(old_vector), hypre_ParVectorLocalVector(old_vector), (HYPRE_Int *)vec_starts); if (!par_vector) { if (print_level) { hypre_printf("par_vector == NULL -- "); hypre_printf("hypre_IJVectorDistributePar\n"); hypre_printf("**** Vector storage is unallocated ****\n"); } hypre_error_in_arg(1); } hypre_ParVectorDestroy(old_vector); hypre_IJVectorObject(vector) = par_vector; return hypre_error_flag; }
HYPRE_Int hypre_AMGSetupStats( void *amg_vdata ) { hypre_AMGData *amg_data = amg_vdata; /* Data Structure variables */ hypre_CSRMatrix **A_array; hypre_CSRMatrix **P_array; HYPRE_Int num_levels; HYPRE_Int num_nonzeros; /* HYPRE_Int amg_ioutdat; char *log_file_name; */ /* Local variables */ HYPRE_Int *A_i; double *A_data; HYPRE_Int *P_i; double *P_data; HYPRE_Int level; HYPRE_Int i,j; HYPRE_Int fine_size; HYPRE_Int coarse_size; HYPRE_Int entries; HYPRE_Int total_entries; HYPRE_Int min_entries; HYPRE_Int max_entries; double avg_entries; double rowsum; double min_rowsum; double max_rowsum; double sparse; double min_weight; double max_weight; double op_complxty=0; double grid_complxty=0; double num_nz0; double num_var0; A_array = hypre_AMGDataAArray(amg_data); P_array = hypre_AMGDataPArray(amg_data); num_levels = hypre_AMGDataNumLevels(amg_data); /* amg_ioutdat = hypre_AMGDataIOutDat(amg_data); log_file_name = hypre_AMGDataLogFileName(amg_data); */ hypre_printf("\n AMG SETUP PARAMETERS:\n\n"); hypre_printf(" Strength threshold = %f\n",hypre_AMGDataStrongThreshold(amg_data)); hypre_printf(" Max levels = %d\n",hypre_AMGDataMaxLevels(amg_data)); hypre_printf(" Num levels = %d\n\n",num_levels); hypre_printf( "\nOperator Matrix Information:\n\n"); hypre_printf(" nonzero entries p"); hypre_printf("er row row sums\n"); hypre_printf("lev rows entries sparse min max "); hypre_printf("avg min max\n"); hypre_printf("======================================="); hypre_printf("==========================\n"); /*----------------------------------------------------- * Enter Statistics Loop *-----------------------------------------------------*/ num_var0 = (double) hypre_CSRMatrixNumRows(A_array[0]); num_nz0 = (double) hypre_CSRMatrixNumNonzeros(A_array[0]); for (level = 0; level < num_levels; level++) { A_i = hypre_CSRMatrixI(A_array[level]); A_data = hypre_CSRMatrixData(A_array[level]); fine_size = hypre_CSRMatrixNumRows(A_array[level]); num_nonzeros = hypre_CSRMatrixNumNonzeros(A_array[level]); sparse = num_nonzeros /((double) fine_size * (double) fine_size); op_complxty += ((double)num_nonzeros/num_nz0); grid_complxty += ((double)fine_size/num_var0); min_entries = A_i[1]-A_i[0]; max_entries = 0; total_entries = 0; min_rowsum = 0.0; max_rowsum = 0.0; for (j = A_i[0]; j < A_i[1]; j++) min_rowsum += A_data[j]; max_rowsum = min_rowsum; for (j = 0; j < fine_size; j++) { entries = A_i[j+1] - A_i[j]; min_entries = hypre_min(entries, min_entries); max_entries = hypre_max(entries, max_entries); total_entries += entries; rowsum = 0.0; for (i = A_i[j]; i < A_i[j+1]; i++) rowsum += A_data[i]; min_rowsum = hypre_min(rowsum, min_rowsum); max_rowsum = hypre_max(rowsum, max_rowsum); } avg_entries = ((double) total_entries) / ((double) fine_size); hypre_printf( "%2d %5d %7d %0.3f %3d %3d", level, fine_size, num_nonzeros, sparse, min_entries, max_entries); hypre_printf(" %4.1f %10.3e %10.3e\n", avg_entries, min_rowsum, max_rowsum); } hypre_printf( "\n\nInterpolation Matrix Information:\n\n"); hypre_printf(" entries/row min max"); hypre_printf(" row sums\n"); hypre_printf("lev rows cols min max "); hypre_printf(" weight weight min max \n"); hypre_printf("======================================="); hypre_printf("==========================\n"); /*----------------------------------------------------- * Enter Statistics Loop *-----------------------------------------------------*/ for (level = 0; level < num_levels-1; level++) { P_i = hypre_CSRMatrixI(P_array[level]); P_data = hypre_CSRMatrixData(P_array[level]); fine_size = hypre_CSRMatrixNumRows(P_array[level]); coarse_size = hypre_CSRMatrixNumCols(P_array[level]); num_nonzeros = hypre_CSRMatrixNumNonzeros(P_array[level]); min_entries = P_i[1]-P_i[0]; max_entries = 0; total_entries = 0; min_rowsum = 0.0; max_rowsum = 0.0; min_weight = P_data[0]; max_weight = 0.0; for (j = P_i[0]; j < P_i[1]; j++) min_rowsum += P_data[j]; max_rowsum = min_rowsum; for (j = 0; j < num_nonzeros; j++) { if (P_data[j] != 1.0) { min_weight = hypre_min(min_weight,P_data[j]); max_weight = hypre_max(max_weight,P_data[j]); } } for (j = 0; j < fine_size; j++) { entries = P_i[j+1] - P_i[j]; min_entries = hypre_min(entries, min_entries); max_entries = hypre_max(entries, max_entries); total_entries += entries; rowsum = 0.0; for (i = P_i[j]; i < P_i[j+1]; i++) rowsum += P_data[i]; min_rowsum = hypre_min(rowsum, min_rowsum); max_rowsum = hypre_max(rowsum, max_rowsum); } hypre_printf( "%2d %5d x %-5d %3d %3d", level, fine_size, coarse_size, min_entries, max_entries); hypre_printf(" %5.3e %5.3e %5.3e %5.3e\n", min_weight, max_weight, min_rowsum, max_rowsum); } hypre_printf("\n Operator Complexity: %8.3f\n", op_complxty); hypre_printf(" Grid Complexity: %8.3f\n", grid_complxty); hypre_WriteSolverParams(amg_data); return(0); }
HYPRE_Int main( HYPRE_Int argc, char *argv[] ) { hypre_ParVector *vector1; hypre_ParVector *vector2; hypre_ParVector *tmp_vector; HYPRE_Int num_procs, my_id; HYPRE_Int global_size = 20; HYPRE_Int local_size; HYPRE_Int first_index; HYPRE_Int num_vectors, vecstride, idxstride; HYPRE_Int i, j; HYPRE_Int *partitioning; double prod; double *data, *data2; hypre_Vector *vector; hypre_Vector *local_vector; hypre_Vector *local_vector2; /* Initialize MPI */ hypre_MPI_Init(&argc, &argv); hypre_MPI_Comm_size(hypre_MPI_COMM_WORLD, &num_procs ); hypre_MPI_Comm_rank(hypre_MPI_COMM_WORLD, &my_id ); hypre_printf(" my_id: %d num_procs: %d\n", my_id, num_procs); partitioning = NULL; num_vectors = 3; vector1 = hypre_ParMultiVectorCreate ( hypre_MPI_COMM_WORLD, global_size, partitioning, num_vectors ); partitioning = hypre_ParVectorPartitioning(vector1); hypre_ParVectorInitialize(vector1); local_vector = hypre_ParVectorLocalVector(vector1); data = hypre_VectorData(local_vector); local_size = hypre_VectorSize(local_vector); vecstride = hypre_VectorVectorStride(local_vector); idxstride = hypre_VectorIndexStride(local_vector); first_index = partitioning[my_id]; hypre_printf("vecstride=%i idxstride=%i local_size=%i num_vectors=%i", vecstride, idxstride, local_size, num_vectors ); for (j=0; j<num_vectors; ++j ) for (i=0; i < local_size; i++) data[ j*vecstride + i*idxstride ] = first_index+i + 100*j; hypre_ParVectorPrint(vector1, "Vector"); local_vector2 = hypre_SeqMultiVectorCreate( global_size, num_vectors ); hypre_SeqVectorInitialize(local_vector2); data2 = hypre_VectorData(local_vector2); vecstride = hypre_VectorVectorStride(local_vector2); idxstride = hypre_VectorIndexStride(local_vector2); for (j=0; j<num_vectors; ++j ) for (i=0; i < global_size; i++) data2[ j*vecstride + i*idxstride ] = i + 100*j; /* partitioning = hypre_CTAlloc(HYPRE_Int,4); partitioning[0] = 0; partitioning[1] = 10; partitioning[2] = 10; partitioning[3] = 20; */ partitioning = hypre_CTAlloc(HYPRE_Int,1+num_procs); hypre_GeneratePartitioning( global_size, num_procs, &partitioning ); vector2 = hypre_VectorToParVector(hypre_MPI_COMM_WORLD,local_vector2,partitioning); hypre_ParVectorSetPartitioningOwner(vector2,0); hypre_ParVectorPrint(vector2, "Convert"); vector = hypre_ParVectorToVectorAll(vector2); /*----------------------------------------------------------- * Copy the vector into tmp_vector *-----------------------------------------------------------*/ /* Read doesn't work for multivectors yet... tmp_vector = hypre_ParVectorRead(hypre_MPI_COMM_WORLD, "Convert");*/ tmp_vector = hypre_ParMultiVectorCreate ( hypre_MPI_COMM_WORLD, global_size, partitioning, num_vectors ); hypre_ParVectorInitialize( tmp_vector ); hypre_ParVectorCopy( vector2, tmp_vector ); /* tmp_vector = hypre_ParVectorCreate(hypre_MPI_COMM_WORLD,global_size,partitioning); hypre_ParVectorSetPartitioningOwner(tmp_vector,0); hypre_ParVectorInitialize(tmp_vector); hypre_ParVectorCopy(vector1, tmp_vector); hypre_ParVectorPrint(tmp_vector,"Copy"); */ /*----------------------------------------------------------- * Scale tmp_vector *-----------------------------------------------------------*/ hypre_ParVectorScale(2.0, tmp_vector); hypre_ParVectorPrint(tmp_vector,"Scale"); /*----------------------------------------------------------- * Do an Axpy (2*vector - vector) = vector *-----------------------------------------------------------*/ hypre_ParVectorAxpy(-1.0, vector1, tmp_vector); hypre_ParVectorPrint(tmp_vector,"Axpy"); /*----------------------------------------------------------- * Do an inner product vector* tmp_vector *-----------------------------------------------------------*/ prod = hypre_ParVectorInnerProd(vector1, tmp_vector); hypre_printf (" prod: %8.2f \n", prod); /*----------------------------------------------------------- * Finalize things *-----------------------------------------------------------*/ hypre_ParVectorDestroy(vector1); hypre_ParVectorDestroy(vector2); hypre_ParVectorDestroy(tmp_vector); hypre_SeqVectorDestroy(local_vector2); if (vector) hypre_SeqVectorDestroy(vector); /* Finalize MPI */ hypre_MPI_Finalize(); return 0; }
HYPRE_Int myBuildParLaplacian( HYPRE_Int argc, char *argv[], HYPRE_Int arg_index, HYPRE_ParCSRMatrix *A_ptr , HYPRE_Int parmprint ) { HYPRE_Int nx, ny, nz; HYPRE_Int P, Q, R; HYPRE_Real cx, cy, cz; HYPRE_ParCSRMatrix A; HYPRE_Int num_procs, myid; HYPRE_Int p, q, r; HYPRE_Real *values; /*----------------------------------------------------------- * Initialize some stuff *-----------------------------------------------------------*/ hypre_MPI_Comm_size(hypre_MPI_COMM_WORLD, &num_procs ); hypre_MPI_Comm_rank(hypre_MPI_COMM_WORLD, &myid ); /*----------------------------------------------------------- * Set defaults *-----------------------------------------------------------*/ nx = 10; ny = 10; nz = 10; P = 1; Q = num_procs; R = 1; cx = 1.; cy = 1.; cz = 1.; /*----------------------------------------------------------- * Parse command line *-----------------------------------------------------------*/ arg_index = 0; while (arg_index < argc) { if ( strcmp(argv[arg_index], "-n") == 0 ) { arg_index++; nx = atoi(argv[arg_index++]); ny = atoi(argv[arg_index++]); nz = atoi(argv[arg_index++]); } else if ( strcmp(argv[arg_index], "-P") == 0 ) { arg_index++; P = atoi(argv[arg_index++]); Q = atoi(argv[arg_index++]); R = atoi(argv[arg_index++]); } else if ( strcmp(argv[arg_index], "-c") == 0 ) { arg_index++; cx = atof(argv[arg_index++]); cy = atof(argv[arg_index++]); cz = atof(argv[arg_index++]); } else { arg_index++; } } /*----------------------------------------------------------- * Check a few things *-----------------------------------------------------------*/ if ((P*Q*R) != num_procs) { hypre_printf("Error: Invalid number of processors or processor topology \n"); exit(1); } /*----------------------------------------------------------- * Print driver parameters *-----------------------------------------------------------*/ if (myid == 0 && parmprint) { hypre_printf(" Laplacian:\n"); hypre_printf(" (nx, ny, nz) = (%d, %d, %d)\n", nx, ny, nz); hypre_printf(" (Px, Py, Pz) = (%d, %d, %d)\n", P, Q, R); hypre_printf(" (cx, cy, cz) = (%f, %f, %f)\n\n", cx, cy, cz); } /*----------------------------------------------------------- * Set up the grid structure *-----------------------------------------------------------*/ /* compute p,q,r from P,Q,R and myid */ p = myid % P; q = (( myid - p)/P) % Q; r = ( myid - p - P*q)/( P*Q ); /*----------------------------------------------------------- * Generate the matrix *-----------------------------------------------------------*/ values = hypre_CTAlloc(HYPRE_Real, 4); values[1] = -cx; values[2] = -cy; values[3] = -cz; values[0] = 0.; if (nx > 1) { values[0] += 2.0*cx; } if (ny > 1) { values[0] += 2.0*cy; } if (nz > 1) { values[0] += 2.0*cz; } A = (HYPRE_ParCSRMatrix) GenerateLaplacian(hypre_MPI_COMM_WORLD, nx, ny, nz, P, Q, R, p, q, r, values); hypre_TFree(values); *A_ptr = A; return (0); }